WPF and Silverlight.ComboBox 如何通过 Binding IsDropDownOpen 实现下拉菜单展开

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 LostFocusevent 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.

 
posted on 2013-09-24 15:55  蔚蓝海  阅读(1064)  评论(0编辑  收藏  举报