CheckComboBox : How to prevent a combobox from closing after a selection is clicked?

后端 未结 2 1397
悲&欢浪女
悲&欢浪女 2021-01-01 05:32

I\'ve got a combobox and it\'s populated with a bunch of checkboxes. I wish the user to be able to click multiple times before the combobox closes (or is closed by the user

2条回答
  •  误落风尘
    2021-01-01 06:10

    Konrad,

    I also decided to use a ComboBox in this manner, because the code was just dead simple. The easiest way I have found to keep the ComboBox popup open is to wire-up to the PreviewMouseDown event of the control in the ComboBox's item template. handle the behavior yourself, and then mark the mouse event handled. Works great for me. In the sample below, each object in FilterItems is a simple view model with a Text property and an IsChecked property.

    
        
            
                
            
        
    
    

    And then my event handler is:

    private void FilterComboBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        var cb = sender as CheckBox;
        if (cb != null)
        {
            cb.IsChecked = !cb.IsChecked;
            e.Handled = true;
        }
    }
    

提交回复
热议问题