使用在 StackOverflow 上找到的概念。请注意,ToggleButton.IsHitTestVisible
绑定到Popup.IsOpen
,与StaysOpen="False"
。这应该意味着触摸外面的任何地方Popup
都会导致它关闭。然而...
触摸/单击ListBoxItem
中的ItemsControl
不会Popup
按预期关闭 。触摸内部的任何其他地方都会Popup
关闭它。根据设置的方式,这似乎没有加起来。
<Grid ClipToBounds="True">
<Border Name="Root">
<ToggleButton x:Name="PART_Toggle"
ClickMode="Release"
IsHitTestVisible="{Binding ElementName=PART_Popup,
Path=IsOpen,
Mode=OneWay,
Converter={StaticResource BooleanInverter}}"/>
</Border>
<Popup x:Name="PART_Popup"
IsOpen="{Binding ElementName=PART_Toggle,
Path=IsChecked}"
PlacementTarget="{Binding ElementName=PART_Toggle}"
StaysOpen="False">
<Grid Background="Transparent">
<Grid>
<!-- Anything here (outside of the Item) -->
<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<!-- Anything in this item template works. The popup does not close -->
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>
</Grid>
</Popup>
</Grid>
有任何想法吗?谢谢。
编辑:已解决
事实证明这是发生的,因为它位于从ListBox
. 在我提出这个问题时,它似乎并不相关,抱歉。