开发者

I want to ask about an implementation detail about combobox in wpf(or silverlight)

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜