Silverlight Binding Linear Order
I stumbled across this Silverlight “feature” today. Silverlight’s binding works in a linear order.
1 | <ComboBox SelectedValue="{Binding SelectedHour, Mode=TwoWay}" ItemsSource="{Binding Hours}" /> |
In the above code, selected value isn’t being set on page load. When I change the ComboBox my SelectedHour ViewModel property was being updated with a new value. This let me know that my binding is working. In further debugging I noticed SelectedHour property was being accessed before the Hours property. The binding was trying to set the selected value but the ComboBox was ignoring it because it didn’t have any values. For fun I tired moving ItemSource binding in front of the SelectedValue binding.
1 | <ComboBox ItemsSource="{Binding Hours}" SelectedValue="{Binding SelectedHour, Mode=TwoWay}" /> |
Everything started working perfectly. Now I know to watch the order of my XAML properties in Silverlight.
Leave a Reply