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