【问题标题】:Show dialog box on shift double click在 shift 双击时显示对话框
【发布时间】:2013-04-24 20:41:39
【问题描述】:

我的 WPF 应用程序中有一个 TextBlock 控件。当用户按住 shift 键并右键双击它时,我想显示一个“复活节彩蛋”。

我已将RoutedUiCommand 添加到我定义了所有命令的应用程序的静态类中。我为我的新命令添加了一个命令绑定:

<UserControl.CommandBindings>
    <CommandBinding CanExecute="ShowDiagnostics_CanExecute" Command="cs:CarSystemCommands.ShowDiagnostics"  Executed="ShowDiagnostics_Executed" />
</UserControl.CommandBindings>

当我创建RoutedUiCommand 时,我指定了RightDoubleClick 的MouseGesture 和ModifierKey 的Shift。到现在为止还挺好。

如何将命令与TextBlock 关联?

【问题讨论】:

    标签: wpf dialog command mouseevent routed-commands


    【解决方案1】:

    您可以使用 InputBindings 和 MouseBinding 在这里描述:http://thejoyofcode.com/Invoking_a_Command_on_a_Double_Click_or_other_Mouse_Gesture.aspx

    【讨论】:

      【解决方案2】:

      将InputBinding 放在将调用该命令的文本块上怎么样?

      【讨论】:

        【解决方案3】:

        我最终做的是将CommandBinding 从UserControl.Resources 移动到TextBlock:

        <TextBlock ...>
            <TextBlock.CommandBindings>
                <CommandBinding CanExecute="ShowDiagnostics_CanExecute" Command="cs:CarSystemCommands.ShowDiagnostics"  Executed="ShowDiagnostics_Executed" />
            </TextBlock.CommandBindings>
        </TextBlock>
        

        现在,除非您按住 shift 键并右键双击 TextBlock,否则什么都不会发生。

        我对其他答案投了赞成票,因为它们也会起作用。

        【讨论】:

          猜你喜欢
          • 2017-02-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多