I’ve been doing some fun Silverlight & Bing Maps development at the moment for ID (more to be revealed later!). Now I have really got stuck in to Silverlight development I figured I would do a blog post on a couple of things I came across and cool functionality I found.
1. Asynchronous calls and updating the UI
One important thing to remember here is that you cannot update the UI from the background thread. If you try and do this you will receive an error message – ‘Invalid cross thread access’. Let’s say you have a web service call in your Silverlight application for example which works asynchronously and falls into the completed event handler once finished. You might want to then update the UI e.g. set some label text once the web service has finished executing.
In order to update the UI you need to use the UI thread. To do this we can use the dispatcher class, here is some example code -
[code lang="csharp"]this.Dispatcher.BeginInvoke(new Action(YourMethodNameHere));[/code]
2. More Mouse events
As well as having the standard ‘Click’ events Silverlight provides much more mouse events. These events allow you to respond to mouse down and mouse up actions. There is also support for mouse move/drag actions.
I have also been working with the SharePoint Client Object Model and Silverlight – I’ll save this one for another blog post!
Here is a sneak peak of what I’m working on for Intelligent Decisioning: