单击Wpf弹出窗口单击其自己的控件模板的项目 [英] Close Wpf Popup On click of item of its own control template
本文介绍了单击Wpf弹出窗口单击其自己的控件模板的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Wpf弹出窗口,它的IsOpen
属性为
I have a Wpf popup ,which has IsOpen
property as
IsOpen="{Binding ElementName=GridItem,Path=IsMouseOver, Mode=OneWay,
UpdateSourceTrigger=PropertyChanged}"
,还有StaysOpen= True
.
在弹出窗口中,我有一个列表框,每个listboxitem都包含一个按钮作为控件模板.我想通过单击按钮来关闭弹出窗口,但是我无法通过单击其中的按钮来关闭弹出窗口.
Inside the popup , I have a list box and each listboxitem contains a button as control template. I want to close the popup on clicking on the button but I am not able to close the popup on by clicking the button inside it.
现在,如果我使用StaysOpen=False
,则会发现两个不同的问题-
Now if I use StaysOpen=False
there are two different issues observed -
- 从一个网格项目更改为另一网格项目时,弹出窗口不 为新悬停的商品生成的.
- 在网格"项目上单击鼠标左键时,弹出窗口被隐藏.
- While changing from one Grid item to other grid item, popup is not generated for newly hovered item.
- On left button down on Grid item , popup gets hidden.
我的代码段如下,
<ItemControl>
<DataTemplate>
<Grid>
<myControl x:Name="GridItem />
<popup IsOpen="{Binding ElementName=GridItem,Path=IsMouseOver, Mode=OneWay,
UpdateSourceTrigger=PropertyChanged}" StaysOpen= True>
<Listbox ItemSource=xyz>
...
<ItemTemplate>
..
<DataTemplate>
<Button>
<!-- Clicking on button needs to close the popup-->
</Button>
</DataTemplate>
</ItemTemplate>
</ListBox>
</poup>
</Grid>
</DataTemplate>
</ItemControl>
在这方面请帮助我.
推荐答案
命名空间
xmlns:i ="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
使用RelativeSource触发
Trigger with RelativeSource
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction
TargetObject="{Binding RelativeSource={RelativeSource AncestorType=Popup}}"
PropertyName="StaysOpen" Value="False"></ei:ChangePropertyAction>
<ei:ChangePropertyAction
TargetObject="{Binding RelativeSource={RelativeSource AncestorType=Popup}}"
PropertyName="IsOpen" Value="False"></ei:ChangePropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
这篇关于单击Wpf弹出窗口单击其自己的控件模板的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文