我在实现 RoutedUICommand 的 RoutedCommand 类中处理命令。如果需要,这将帮助我通过检查他们的 CanExecute 和 Execute 来阻止或覆盖命令。我可以覆盖 EditingCommand、ApplicationCommand 等。我什至无法处理的命令之一是 Ctr + Spacebar。它是 MediaCommand 还是我找不到的其他类型?我猜它是在其他地方处理的,这就是为什么我无法控制它。
问问题
531 次
2 回答
2
您可以创建自己的自定义命令,也可以简单地为预定义命令添加新手势,例如:
public Window1()
{
InitializeComponent();
ApplicationCommands.Find.InputGestures.Add(new KeyGesture(Key.Space, ModifierKeys.Control));
CommandBinding commandBinding = new CommandBinding(ApplicationCommands.Find, myCommandHandler);
this.CommandBindings.Add(commandBinding);
}
private void myCommandHandler(object sender, ExecutedRoutedEventArgs args)
{
MessageBox.Show("Command invoked!");
}
于 2010-04-09T15:44:58.833 回答
0
我没有太多使用 WPF 命令的经验,但尝试为 Ctrl 和空格键创建自己的自定义命令。
请参阅本教程:http ://www.switchonthecode.com/tutorials/wpf-tutorial-command-bindings-and-custom-commands
于 2009-11-25T23:31:04.183 回答