I like to populate a Listbox with a List<T> as the ItemsControl.ItemsSource. It seems like as soon as I set the ItemsSource, my event handler for SelectionChanged fires, and my first item in the list is selected. I’d like to start the list up with nothing selected by default, and not have to try to handle the event until the user actually clicks on a member of the list.
This is in a PopUp window, so each time the list appears, it should be set to ‘nothing selected’, i.e. SelectedIndex == -1.
I suppose I could remove the event handler in the code, populate the list, set it to -1, and then add the event handler again, but seems like a kind of messy way to do it.
Psychic debugging, do you have
ListBox.IsSynchronizedWithCurrentItemset toTruein the XAML?Given:
And:
I receieve a
NotImplementException, meaningIsSynchronizedWithCurrentItem="True"is a likely culprit.We can test hypothesis this by removing this attribute or setting it to false, which will not throw an exception until the user clicks on an item.