我正在尝试创建一个下拉控件,其中包含一个ToggleButton和一个带有TabControl的Popup控件.我的问题是,Popup不会自动关闭,除非我点击其中的某个控件.
考虑下面的示例,其中弹出窗口包含TabControl,TabControl本身包含TabItem内的Calendar控件.
预期的行为是Popup在失去焦点时关闭(即点击容器窗口),但是为了让弹出窗口触发LostFocus事件并因此关闭,我必须首先单击Calendar控件上的一个箭头按钮.
<UserControl
x:Class="DropDownExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Grid>
<ToggleButton x:Name="ToggleButton"
ClickMode="Press">Example</ToggleButton>
<Popup x:Name="Popup"
Placement="Bottom"
AllowsTransparency="True"
StaysOpen="False"
PopupAnimation="Slide"
FocusManager.IsFocusScope="false">
<TabControl x:Name="TabControl"
MinHeight="200">
<TabItem>
<Calendar />
</TabItem>
</TabControl>
</Popup>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
弹出窗口的打开/关闭在ToggleButton的Checked/Unchecked事件中进行控制.