The code is doing exactly what you have asked it to do. When the selection changes, default is no selection, the
SelectionChanged
is fired from the ctor method.
IF you set a breakpoint on the line
CboCustomer.SelectedIndex = 2;
then step through the execution line by line, you will see this happening. It is call debugging.
So, if this is NOT the intended behavior expected, then you need to add a flag to shortcut the
SelectionChanged
event. Here is how you would do that:
private bool isLoading;
public ProfileScreen(User user)
{
isLoadiing = true;
isLoadiing = false;
}
Now when you don't want events firing upon initialization you do the following:
private void CboCustomer_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (isloading) return;
}