What event handler to use for ComboBox Item Selected (Selected Item not necessarily changed)

后端 未结 12 1563
囚心锁ツ
囚心锁ツ 2020-12-13 08:48

Goal: issue an event when items in a combobox drop down list is selected.

Problem: Using \"SelectionChanged\", however, if the user

12条回答
  •  执笔经年
    2020-12-13 09:22

    Every ComboBoxItem instance has PreviewMouseDown event. If you will subscribe your custom handler on this event on every ComboBoxItem you will have opportunity to handle every click on the dropdown list.

    // Subscribe on ComboBoxItem-s events.
    comboBox.Items.Cast().ToList().ForEach(i => i.PreviewMouseDown += ComboBoxItem_PreviewMouseDown);
    
    private void ComboBoxItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
         // your handler logic...         
    }
    

提交回复
热议问题