crash in ComboBox coerce (not my code)

前端 未结 5 1021
臣服心动
臣服心动 2020-12-20 13:20

I got the stack trace below reported from a customer. I don\'t know how to reproduce this. My WPF application has a fair number of ComboBoxes; I\'m not sure how to determine

5条回答
  •  余生分开走
    2020-12-20 14:12

    I got the same error with similar code to what maiksaray shared. For me, the NullReferenceException at CoerceIsSelectionBoxHighlighted only happened on Windows 10, not on my Windows 7 dev machine. It only happened the first time the combo box was clicked to open.

    In my case, I was programmatically opening and closing the combobox when the view loaded:

    public MyView()
    {
        InitializeComponent();
        Loaded += OnLoaded;
    }
    
    private void comboBox1_DropDownOpened(object sender, EventArgs e)
    {
        comboBox1.ItemsSource = MyClass.GetComboBoxList();
    }
    
    private void OnLoaded(object sender, RoutedEventArgs e)
    {
       comboBox1.IsDropDownOpen = true;
       comboBox1.IsDropDownOpen = false;
    }
    

    I was doing this as the workaround to another problem, described here: http://blog.elgaard.com/2009/09/03/wpf-making-combo-box-items-disabled-also-when-accessed-using-the-keyboard/

    The error happened after DevicesComboBox_DropDownOpened completed. However, it only happened with the OnLoaded code present. If I commented out Loaded += OnLoaded, then I didn't get the error.

    The solution for me was to simply avoid programmatically opening and closing the ComboBox.

提交回复
热议问题