Thursday, 25 April 2013

XAML - SelectedItem in ComboBox doesn't work

I'm currently working on a small Windows Store app. The app uses mainly default controls, with ComboBox being one of them. Recently I had a problem with selecting a default value in my ComboBox.

My XAML code looked like this:

In the design view this actually showed the correct selected item, however it didn't work when the app was ran.


The solution was actually very trivial. If you take a look at my code you'll see that the SelectedItem property is defined before the ItemSource property. It came out that the order does matter, so the SelectedItem should be defined after the ItemSource.