我的应用程序中有两个嵌套网格(FrameworkElement)项。
<UserControl xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<Grid x:name="OuterGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction x:Name="TheOuterCommand" Command="{Binding OuterCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid x:name="InnerGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction x:Name="TheInnerCommand" Command="{Binding InnerCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
</Grid>
</UserControl>每个InvokeCommands都附加到视图模型中的一个InvokeCommands(来自棱镜库)。
OuterCommand = new DelegateCommand(OuterCommandMethod, e => true);
InnerCommand = new DelegateCommand(InnerCommandMethod, e => true);目前,由于MouseLeftButtonEvent没有在InnerGrid级别处理,InnerGrid上的EventTrigger也会触发OuterGrid上的事件。
我是否可以通知EventTrigger,它已经被处理,并且不应该一直泡到OuterGrid?
目前,我所能做的就是在InnerGrid周围设置一个包装器InnerGrid,它使用XAML代码中的一个事件来设置要处理的事件。还有人有其他的想法吗?
-编辑---最后,我在我的应用程序中加入了MVVM,并用RelayCommand替换了InvokeCommandAction。这是我想要的。我将把科比的回答作为给我建议的赢家。
发布于 2011-09-22 00:19:51
您最好的选择是将事件args传递给Command,然后使用事件args标记处理的事件。您可以通过遵循这里的例子来做到这一点。
发布于 2012-11-28 17:09:11
我们通过添加名为EventTrigger的依赖项属性来扩展IsInner,然后始终在内部EventTrigger中设置一个静态标志。外部EventTrigger将取消标志,如果设置了标志,则返回。这是非常容易写和工作很好。
https://stackoverflow.com/questions/7507805
复制相似问题