I am working on implementing global shortcut keys (i.e. application wide shortcut keys) for my WPF application, which has multiple windows. To achieve that, I am doing:
CommandManager.RegisterClassInputBinding(typeof(Window), o); // o is just a keybinding
That is, I am trying to register a keybinding with the Window class so that my shortcut key works, no matter what window is active. But my code throws the following exception on reaching this line:
System.InvalidOperationException was unhandled by user code
Message=This Freezable cannot be frozen.
Source=WindowsBase
StackTrace:
at System.Windows.Freezable.Freeze()
at System.Windows.Input.CommandManager.RegisterClassInputBinding(Type type, InputBinding inputBinding)
This is how the keybinding o
is created:
KeyBinding o = new KeyBinding()
{
Command = f,
CommandParameter = popup,
Key = Key.Q,
Modifiers = ModifierKeys.Control
};
popup
is just a wpf popup. f
is an object of a class that implements ICommand
interface.
I have looked up similar questions on StackOverflow and they seem to be caused by the freezable object SolidColorBursh. I don't think that that applies to my case. Does anyone know what is going on?