【发布时间】:2011-12-01 03:57:19
【问题描述】:
我有一个具有菜单键盘快捷键和文本框的应用程序。我希望在文本框获得焦点时禁用键盘快捷键,但我想不出一个简单的方法来做到这一点。我可以处理文本框的 PreviewKeyDown 事件,但发送 KeyDown 事件不会触发 TextInput 事件,因此我必须自己手动触发 TextInput 事件,并且我必须确保每个文本框都覆盖PreviewKeyDown 事件并创建一个 TextInput 事件。
这是在文本框有焦点时抑制菜单键盘快捷键的唯一方法,还是有其他不易出错的方法?
编辑:
这是我添加键盘快捷键的方法:
var kgc = new NuiWpfCore.Input.UnrestrictedKeyGestureConverter(); // allows gestures without modifier keys
var result = kgc.ConvertFromString(s) as NuiWpfCore.Input.UnrestrictedKeyGesture;
m_KeyBinding = new KeyBinding();
m_KeyBinding.Command = KeyBindingCommand;
m_KeyBinding.Modifiers = result.Modifiers;
m_KeyBinding.Key = result.Key;
m_Parent.InputBindings.Add(m_KeyBinding); // m_Parent is of type UIElement
【问题讨论】:
标签: wpf textbox keyboard-shortcuts