1

I am now working on a custom control in wpf. I used Combobox as parent. I wonder how does my custom Combobox works like its parent. How can I click any part of my screen, and the dropdown part of my combobox can be closed...I tried many ways, but neither are work properly.

Can somebody give some articles or something else?

3
  • 1
    There is a part of a ComboBox that is called "Popup". It has a property "StaysOpen" that indicates whether ComboBox should be closed if user clicks anywhere outside.
    – vortexwolf
    Jan 1, 2011 at 15:08
  • Thanks very much! I'll try. But I want to know the internal implementations
    – jiluo
    Jan 1, 2011 at 17:36
  • Ok, I've posted an answer with 2 links. Probably my explanation isn't obvious, but I don't have a code of a WPF ComboBox, only Silverlight.
    – vortexwolf
    Jan 1, 2011 at 19:48

1 Answer 1

1

Here is standard control templates of a ComboBox: WPF and Silverlight.

In the WPF example the Popup and the ToggleButton (the arrow on the right) are bound with the property IsDropDownOpen:

<Popup IsOpen="{TemplateBinding IsDropDownOpen}" ...

<ToggleButton IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ...

A class Popup has the property StaysOpen that isn't specified in the standard template of a ComboBox and has a default value true. It follows that there is a subscription to the LostFocus event in the internal implementation of a ComboBox, that sets IsDropDownOpen=false every time when the control lose a focus.

Silverlight has no bindings in xaml, but you will find the same sequence if you open the assembly in .Net Reflector.

1
  • I have read the implementation of combobox in wpf, My own implementation doesn't need the togglebutton, so I'll not use the IsDropDownOpen, I'll handle the dropdownopen myself. Thanks for you answer!
    – jiluo
    Jan 2, 2011 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.