I have a CheckBox chkAddToGroup which activates this ComboBox cmbGroup.
If chkAddToGroup is being checked the following happens:
ObservableCollection<Group> groupColl = new ObservableCollection<Group>() { };
foreach (Group g in GroupHandler.GroupList)
{
    groupColl.Add(g);
}
cmbGroup.ItemsSource = groupColl;
cmbOrganisation.SelectedIndex = 0;
cmbGroup.IsEnabled = true;
As you can see cmbGroup is attached to groupColl (DisplayMemberPath is set in an external Style).
The problem occurs if I try to reset my form. Therefor I have a Button btnReset.
If the user clicks on btnReset the application does this:
chkAddToGroup_Unchecked(this, null);
In chkAddToGroup_Unchecked(object sender, RoutedEventArgs e) following happens then:
private void chkAddToGroup_Unchecked(object sender, RoutedEventArgs e)
    {
        cmbGroup.ItemsSource = null;
        cmbGroup.IsEnabled = false;
        cmbGroupRole.ItemsSource = null;
        cmbGroupRole.IsEnabled = false;
    }
As you can see I set ItemsSource = null in order to clear the combobox. (don't know any other way atm)
If the user didn't check the checkbox before hitting the reset button then nothing special happens.
But if the user did check the checkbox and selected an item then there is a NullReferenceException as soon as the application tries to execute cmbGroup.ItemsSource = null;
Why does this happen? Any idea?
 
     
     
    