0
Answer

WPF Combobox Close When Click on Outside

Rajesh Kumar

Rajesh Kumar

11y
2.4k
1
Hi...

          



I would like to create custom control that will look like standard WPF ComboBox, but instead of instead of having an ItemsPresenter in the popup there will be another custom control. So, I created a new class that derives from System.Windows.Controls.Control, added a IsDropDownOpen property and created a style that is actually a copy of default ComboBox style (main idea is that thePopup.IsOpen and ToggleButton.IsPressed properties are bound to the IsDropDownOpenproperty of the control).

The problem is that the Popup is not closed when I click outside of the control.

I took a look at the ComboBox class in the Reflector and found out that ComboBox used some logic to update the IsDropDownOpen property when it loses mouse capture. But that code uses some internal classes. Is there any alternative way to determine if the user clicked outside of the control and close thePopup?


Thanks 

RAjesh