Tag: DataBinding

Custom Silverlight TextBox control that immediately updates DataBound Text property in TwoWay binding

Standard Silverlight TextBox control is very useful but has one strange behavior: if you use TwoWay data binding and bind some property to controls Text property, when users type text into the control, this change is not propagated to the bound property until the control loses its focus. This can be very annoying if you have MVVM application and you have some kind of real-time filter that needs to update some data as-you-type. Problem is that TextBox control does not call BindingExpression.UpdateSource when its Text property is changed so we have to do that manually in order to fix this…

Unit Testable WCF Web Services in MVVM and Silverlight 4

In all my previous MVVM in Silverlight 4 posts i was avoiding to address one painful aspect of the Silverlight: calling WCF Web Services. And it was not without reason. Lets face it, consuming WCF Web Services from your Silverlight application can be pretty hard. I mean hard to do it in a clean way off course. Yes we all know how to create a Silverlight enabled WCF Web Service from Visual Studio but things become messy from that point. First question is how to invoke methods of the web service? Should we use Add Web Service Reference from the Visual…

Binding UI Events from View to commands in ViewModel in Silverlight 4

In previous two posts we covered wiring up the Views and ViewModels and Blendability and showing ModalDialogs in MVVM way. Today we will touch another problem that people starting with MVVM very often fail to address properly: Handling the UI Events of the View in the ViewModel while avoiding placing any logic in code behind of the View. So our design goals for this post are: We want to be able to wire-up UI Events to the commands in ViewModel via DataBinding in Xaml without any code behind in the View View should not be aware of the ViewModel’s type…