Dustin Horne

Developing for fun...

UI Updates With Databinding and INotifyPropertyChanged

Today I'm going to show you how easy it is to leverage the power of property binding in Silverlight.  I'm going to provide a very simplistic example that, while not very useful in itself, I hope will spark your imagination and show you how easy it is.  In my example I'm going to show you how to capture the position of the mouse over a canvas and keep the live updated mouse position in a separate class.  In addition, I'll show you how to update your UI directly (moving a box with the mouse and using labels to show the current mouse position) without directly wiring a single event to those controls in your page codebehind!

Before the MVVM pattern folks start foaming at the mouth over this article, I'd like to point out that this is meant to be a very simple demonstration and is not meant to be an MVVM application.  However, I will introduce you to a few concepts along the way that you will leverage in the MVVM design pattern.  I'm going to briefly introduce you to the DataContext object and I'll be storing the mouse data in a separate class but I will not create a complete Model-View-ViewModel separation for this example.  I will, however be encouraging a separation of UI and logic that will serve as a good starting place when you decide to dive into the world of MVVM.  Now, on with the show...

 More...