在每个窗口实例中创建新的键绑定:
KeyBinding n = new KeyBinding() { Modifiers = ModifierKeys.Control, Key = Key.N };
KeyBinding o = new KeyBinding() { Modifiers = ModifierKeys.Control, Key = Key.O };
KeyBinding s = new KeyBinding() { Modifiers = ModifierKeys.Control, Key = Key.S };
KeyBinding w = new KeyBinding() { Modifiers = ModifierKeys.Control, Key = Key.W };
BindingOperations.SetBinding(n, InputBinding.CommandProperty, new Binding("NewProgramCommand"));
BindingOperations.SetBinding(o, InputBinding.CommandProperty, new Binding("OpenProgramCommand"));
BindingOperations.SetBinding(s, InputBinding.CommandProperty, new Binding("SaveProxyCommand"));
BindingOperations.SetBinding(w, InputBinding.CommandProperty, new Binding("CloseProxyCommand"));
InputBindings.AddRange(new KeyBinding[4] { n, o, s, w });
…并确保每个窗口
DataContext
给一个
MainWindowController
或者定义命令的任何类型。