Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf AvaloneEdit::Ctrl+;I键绑定不';行不通_Wpf_Wpf Controls_Key Bindings_Avalonedit - Fatal编程技术网

Wpf AvaloneEdit::Ctrl+;I键绑定不';行不通

Wpf AvaloneEdit::Ctrl+;I键绑定不';行不通,wpf,wpf-controls,key-bindings,avalonedit,Wpf,Wpf Controls,Key Bindings,Avalonedit,我正在使用AvalonEdit(惊喜地)创建一个文本编辑器。我在声明中添加了键绑定: <ae:TextEditor x:Name="TextEditor" ... > <ae:TextEditor.InputBindings> <KeyBinding Command="ToggleBold" Key="B" Modifiers="Control"/> <KeyBinding Command="ToggleItalic" Ke

我正在使用AvalonEdit(惊喜地)创建一个文本编辑器。我在声明中添加了键绑定:

<ae:TextEditor x:Name="TextEditor" ... >
   <ae:TextEditor.InputBindings>
      <KeyBinding Command="ToggleBold" Key="B" Modifiers="Control"/>
      <KeyBinding Command="ToggleItalic" Key="I" Modifiers ="Control"/>
      <!-- other bindings -->
   </ae:TextEditor.InputBindings>
</ae:TextEditor>

我有大约20个ish按钮与典型的命令关联,它们都在工作,包括
EditingCommands.ToggleItalic
。我有与命令相关联的键绑定,它们都按预期工作,只有
Ctrl+I
例外。我无法使Ctrl+I键绑定组合与任何命令一起使用(例如,尝试将其与ToggleBold一起使用)

要明确的是:

  • 例如,如果我绑定的对象不是
    Ctrl+I
    -
    Ctrl+Shift+I
    ,则用于
    ToggleItalic
    KeyBinding
    可以正常工作
  • Ctrl+I
    组合似乎不适用于任何键绑定

  • 有人知道为什么会这样吗?我不想偏离默认的键绑定-
    Ctrl+I
    ,因为对于我们这些喜欢键盘快捷键的人来说,切换斜体是根深蒂固的。

    AvalonEdit控件中的
    Ctrl+I
    键手势已经与
    IndentSelection
    AvalonEdit命令相关联(这是一个RoutedCommand,因此可以有一个或多个输入手势)

    如果查看
    AvalonEditCommands
    类,您会发现以下代码:

    public static readonly RoutedCommand IndentSelection = new RoutedCommand( 
        "IndentSelection", typeof(TextEditor), 
        new InputGestureCollection { 
            new KeyGesture(Key.I, ModifierKeys.Control) 
    });
    
    因此,您必须删除IndentSelection命令绑定(在
    EditingCommandHandler
    类中),以便对另一个命令使用
    Ctrl+I
    键手势

    编辑 我想您可以通过清除
    应用程序中IndentSelection命令的
    InputGestureCollection
    来解决问题。onStart
    方法:

    protected virtual void OnStartup(StartupEventArgs e)
    {
        AvalonEditCommands.IndentSelection.InputGestures.Clear();
        /* If you want now you can add a new inputgesture */
        /* The rest of your code... */
    }
    

    我没有测试这个解决方案,但我认为它可以工作。

    我如何访问该类?我在任何TextEditor属性上都找不到它的实例……它们隐藏在哪里?@ScottSEA,我用另一个(更简单的)解决方案编辑了我的答案。