之前我一直在使用
this.CommandBindings.Add(
new CommandBinding(ApplicationCommands.Copy, this.cmdCopy_Executed, this.cmdCopy_CanExecute))
cmdCopy_Executed是一个非静态函数,但我看到有人使用
static MyControl()
{
CommandBinding binding =
new CommandBinding(ApplicationCommands.Save, CommandHandler);
CommandManager.RegisterClassCommandBinding(typeof(MyControl), binding);
}
private static void CommandHandler(object target, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Command Handled!");
}
命令绑定(CommandBinding)是静态的。是否有一种优选于另一种?