wpfxamlmvvm-lighteventtocommand

Should MouseRightButtonDown work with EventToCommand?


Is the RightMouseDownEvent expected to work with EventToCommand?

I can bind a Command with PreviewMouseRightUp and PreviewMouseRightDown, but MouseRightButtonDown does nothing. Am I using the wrong event name -- is it that simple?

In the xaml -- i have both events bound to the same handler -- only one works (Preview...Up). I comment out each in turn, but only the Preview works.

Thoughts? Thanks!

            <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>

Solution

  • Some controls handle the MouseRightButtonDown event and doesn't let it propagate (e.g. MenuItem). You can test this easily if you're calling a code behind method instead of using a trigger and see if you'll reach a breackpoint in that method.

    In your xaml:

        MouseRightButtonDown="UIElement_OnMouseRightButtonDown"
    

    In your code behind:

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