<分区>
我正在为我的 WPF 应用程序实现全局快捷键(即应用程序范围的快捷键),它有多个窗口。为实现这一目标,我正在做:
CommandManager.RegisterClassInputBinding(typeof(Window), o); // o is just a keybinding
也就是说,我正在尝试向 Window 类注册一个键绑定(bind),以便无论哪个窗口处于事件状态,我的快捷键都可以使用。但是我的代码在到达这一行时抛出以下异常:
System.InvalidOperationException was unhandled by user code
Message=This Freezable cannot be frozen.
Source=WindowsBase
堆栈跟踪:
at System.Windows.Freezable.Freeze()
at System.Windows.Input.CommandManager.RegisterClassInputBinding(Type type, InputBinding inputBinding)
这就是键绑定(bind) o
的创建方式:
KeyBinding o = new KeyBinding()
{
Command = f,
CommandParameter = popup,
Key = Key.Q,
Modifiers = ModifierKeys.Control
};
popup
只是一个 wpf 弹出窗口。 f
是实现了 ICommand
接口(interface)的类的对象。
我在 StackOverflow 上查找了类似的问题,它们似乎是由可卡住对象 SolidColorBursh 引起的。我认为这不适用于我的情况。有谁知道这是怎么回事吗?