Rajesh Kumar

Rajesh Kumar

  • NA
  • 39
  • 12.3k

WPF Combobox Close When Click on Outside

May 27 2013 5:32 AM
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 the Popup.IsOpen and ToggleButton.IsPressed properties are bound to the IsDropDownOpen property 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 the Popup?
 
 


Thanks 

RAjesh


Answers (1)