[英]Setting e.handled = true in the MouseDoubleClick event in UserControl bubbles to Parent Control
I have developed a WPF application following MVVM pattern. 我已经按照MVVM模式开发了WPF应用程序。
UserControl 用户控件
It has a textBox control and I have hooked up MouseDoubleClick . 它有一个textBox控件,我已经连接了MouseDoubleClick 。
private void textbox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
Parent 父级
<ListView>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding DoubleClickCommand}"
CommandParameter="{Binding data}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListView>
The problem is that even after setting e.Handled = true, DoubleClickCommand is called in the main view. 问题在于,即使在设置e.Handled = true之后,也会在主视图中调用DoubleClickCommand。 I want DoubleClickCommand not to be fired when e.Handled = true.
我希望在e.Handled = true时不触发DoubleClickCommand。
Any help would be great. 任何帮助都会很棒。
Just make sure to use the same DoubleClickCommand at in both the parent and the usercontrol, let's say this is your usercontrol : 只要确保在父控件和usercontrol中都使用相同的DoubleClickCommand,就可以说这是您的usercontrol:
<UserControl x:Class="WpfApp4.UserControl1"
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp4"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" MouseDoubleClick="UserControl1_OnMouseDoubleClick">
<Grid>
<TextBox Width="100" />
</Grid>
The Parent should look something like this: 家长应该看起来像这样:
<Window ... DataContext="{Binding ParentViewModel}" Name="Main">
<Grid>
<ListView ItemsSource="{Binding ItemsCollection}">
<ListView.ItemTemplate>
<DataTemplate>
<local:UserControl1>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding DoubleClickCommand,ElementName=Main}"
CommandParameter="{Binding data}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</local:UserControl1>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
Now the Handled property will work just fine. 现在,Handled属性可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.