MouseRightButtonDown应该与EventToCommand一起使用吗?

时间:2014-03-18 15:21:26

标签: wpf xaml mvvm-light eventtocommand

RightMouseDownEvent是否可以与EventToCommand一起使用?

我可以使用PreviewMouseRightUp和PreviewMouseRightDown绑定一个Command,但MouseRightButtonDown什么都不做。我使用错误的事件名称 - 这很简单吗?

在xaml中 - 我将两个事件绑定到同一个处理程序 - 只有一个工作(预览...向上)。我依次评论每个,但只有预览工作。

思考?谢谢!

            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                <cmd:EventToCommand Command="{Binding SetActivePaneCommand}"    CommandParameter="{Binding PaneOne}" PassEventArgsToCommand="False" />
                <cmd:EventToCommand Command="{Binding ListSelectionChangedCommand}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseRightButtonDown">
                    <cmd:EventToCommand Command="{Binding PreviewMouseRightButtonUpCommand}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
                <i:EventTrigger EventName="PreviewMouseRightButtonUp">
                    <cmd:EventToCommand Command="{Binding PreviewMouseRightButtonUpCommand}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

1 个答案:

答案 0 :(得分:1)

某些控件处理MouseRightButtonDown事件并且不允许它传播(例如MenuItem)。如果您在方法后面调用代码而不是使用触发器,那么您可以轻松地对此进行测试,看看您是否会在该方法中达到breackpoint。

在你的xaml中:

    MouseRightButtonDown="UIElement_OnMouseRightButtonDown"

在你的代码背后:

    private void UIElement_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
    { }