【问题标题】:KeyBinding for gestures CTRL+C and CTRL+ V do not work?手势 CTRL+C 和 CTRL+V 的键绑定不起作用?
【发布时间】:2012-10-29 22:16:43
【问题描述】:

我的视图模型中有一些 ICommand,我想使用键盘绑定将它们绑定到我的用户控件。我面临的问题是,当我使用 CTRL + CCTRL + V 来在我的用户控件中绑定我的复制和粘贴命令。我应该覆盖它们还是什么?

<UserControl.InputBindings>
    <KeyBinding Gesture="CTRL+C" Command="{Binding CopyCommand}" />
</UserControl.InputBindings>

【问题讨论】:

  • 例如,如果将手势更改为“CTRL+N”,是否有效?
  • @SuperOli 是的,确实如此,但我必须使用众所周知的命令进行复制和粘贴。
  • 您是否尝试过使用CommandBindings?像这样:&lt;UserControl.CommandBindings&gt; &lt;CommandBinding Command="Cut" CanExecute="Cut_CanExecute" Executed="Cut_Executed" /&gt; &lt;CommandBinding Command="Copy" CanExecute="Copy_CanExecute" Executed="Copy_Executed" /&gt; &lt;CommandBinding Command="Paste" CanExecute="Paste_CanExecute" Executed="Paste_Executed" /&gt; &lt;CommandBinding Command="Delete" CanExecute="Delete_CanExecute" Executed="Delete_Executed" /&gt; &lt;/UserControl.CommandBindings&gt;
  • 用户控件中是否有文本框或类似内容,在您按下 Ctrl-C 时具有焦点?如果是这样,那么文本框将在 UserControl 之前捕获命令。
  • 这似乎是一个类似的问题:stackoverflow.com/questions/12941707/…

标签: c# wpf xaml key-bindings


【解决方案1】:

这对我来说就像一个魅力:

<!--COPY-->
<UserControl.InputBindings>
    <KeyBinding Key="C" Modifiers="Ctrl" Command="{Binding CopyToStackCommand}" />
</UserControl.InputBindings>

<!--PASTE-->
<UserControl.InputBindings>
    <KeyBinding Key="V" Modifiers="Ctrl" Command="{Binding PasteFromStackCommand}" />
</UserControl.InputBindings>

【讨论】:

    【解决方案2】:
    <KeyBinding Key="C" Modifiers="Ctrl" Command="Copy" CommandParameter="{Binding copy}" />
    

    【讨论】:

      猜你喜欢
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多