Wpf AvaloneEdit::Ctrl+;I键绑定不';行不通
我正在使用AvalonEdit(惊喜地)创建一个文本编辑器。我在声明中添加了键绑定: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
<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,我用另一个(更简单的)解决方案编辑了我的答案。