When I added the SelectionChanged event and of course the method in the code to handle the event to the following combobox:
....
Put OrderBox.SelectionChanged+=OrderBox_OnSelectionChanged;
in the MainWindow
constructor and remove the SelectionChanged
attribute in your xaml.
When a form is loaded using the InitializeComponent();
, the combo boxes on that pages with be set to (usually) their item at the index of -1, unless you explicitly set it otherwise. Either way, the selected item changes to its default when the form is initialized and the SelectionChanged
event hits. You could work around the event being hit by putting a line of error handling:
private void OrderBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (OrderBox.SelectedItem != null)
{
//your code
}
}