Two obvious solutions to this would be 1) Wait until the Loaded event of the Window/Page/UserControl which contains the ComboBox and hook up SelectionChanged there...eg in the constructor:
// set the inital selected index for the combo box here...
this.Loaded += (s, args) =>
{
cmbBox.SelectionChanged +=
new SelectionChangedEventHandler(HandleChanged);
};
or 2) Check that the ComboBox has loaded in the selection changed handler before doing anything and return if it hasn't...eg in the handler:
if (!cmbBox.IsLoaded)
return;
I would prefer number 1 as it doesn't require the check every time the SelectionChanged handler is fired.