【问题标题】:Should MouseRightButtonDown work with EventToCommand?MouseRightButtonDown 应该与 EventToCommand 一起使用吗?
【发布时间】:2014-03-18 15:21:25
【问题描述】:

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

我可以将命令与 PreviewMouseRightUp 和 PreviewMouseRightDown 绑定,但 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>

【问题讨论】:

    标签: wpf xaml mvvm-light eventtocommand


    【解决方案1】:

    一些控件处理 MouseRightButtonDown 事件并且不让它传播(例如 MenuItem)。如果您调用的是代码隐藏方法而不是使用触发器,则可以轻松测试这一点,看看您是否会到达该方法中的断点。

    在您的 xaml 中:

        MouseRightButtonDown="UIElement_OnMouseRightButtonDown"
    

    在你的代码后面:

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

    【讨论】:

    • 一旦我重新安装了 Visual Studio,我会尝试一下 -- 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多