WPF Popup IsOpen问题 [英] WPF Popup IsOpen issue
问题描述
使用在StackOverflow上的此处找到的概念. 请注意,ToggleButton.IsHitTestVisible
已绑定到Popup.IsOpen
,并带有StaysOpen="False"
..这应该意味着,触摸Popup
的外部之外的任何地方都会导致其关闭.但是...
Using a concept found here on StackOverflow. Note that the ToggleButton.IsHitTestVisible
is bound to Popup.IsOpen
, with StaysOpen="False"
. This should mean that touching anywhere outside the Popup
would cause it to close. However...
触摸/单击ItemsControl
中的ListBoxItem
不会按预期关闭Popup
.触摸Popup
内的其他任何地方都可以将其关闭.根据它的设置方式,这似乎并没有加起来.
Touching/Clicking on an ListBoxItem
in the ItemsControl
won't close the Popup
, as is intended. Touching anywhere else within the Popup
does close it. That doesn't seem to add up, according to how this is set up.
<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
派生的自定义控件中.抱歉,在我提出这个问题时似乎并不相关.
Turns out this was happening because it was inside a custom control which was derived from ListBox
. It didn't seem relevant at the time I made this question, sorry.
推荐答案
发生这种情况是因为它位于自ListBox派生的自定义控件中.抱歉,在我提出这个问题时,这似乎并不重要.
Turns out this was happening because it was inside a custom control which was derived from ListBox. It didn't seem relevant at the time I made this question, sorry.
这篇关于WPF Popup IsOpen问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!