A long time ago, in a galaxy far away (well, 2 years ago, in a galaxy called Silverlight), we ran into a very unexpected bug in the XAML framework, or rather: in the way XAML is parsed.
Ever ran into the situation where you’re binding properties of any control accepting an ItemsSource & SelectedItem, and then setting the SelectedItem’s bound value in your ViewModel to ensure there’s something selected the first time a user navigates to your view? Should be easy, right? Bind the ItemsSource to an ObservableCollection<T>, bind SelectedItem to a property of type T, and in your ViewModel, set the bound value to, for example, the first item in the ObservableCollection.
This perfectly works… IF you’ve declared your ItemsSource binding in XAML before the SelectedItem binding.
So, this works:
ItemsSource="{Binding MyPictures}" SelectedItem="{Binding CurrentPicture, Mode=TwoWay}"
And this doesn’t:
SelectedItem="{Binding CurrentPicture, Mode=TwoWay}" ItemsSource="{Binding MyPictures}"
In the second case, setting the SelectedItem’s bound value will not be reflected in your view. Note that this is only the case the first time: after the user has selected an item in the list, setting the bound value in your ViewModel works as expected.
Looks like a bug to me, or at least unexpected/undocumented behavior, and it’s only a minor annoyance – but if you run into it, here’s the solution 🙂