当前位置:首页 > Windows程序 > 正文

【WPF】命令系统

2021-05-26 Windows程序

public class MyTextBox:TextBox { static MyTextBox() { CommandManager.RegisterClassCommandBinding(typeof(MyTextBox), new CommandBinding(MyCommands.MyRoutedCommand, Command_Executed, Command_CanExecute)); } private static void Command_CanExecute(object sender, CanExecuteRoutedEventArgs e) { MyTextBox myTextBox = (MyTextBox)sender; e.CanExecute = !string.IsNullOrWhiteSpace(myTextBox.Text); } private static void Command_Executed(object sender, ExecutedRoutedEventArgs e) { MyTextBox myTextBox = (MyTextBox)sender; myTextBox.Foreground = new SolidColorBrush(Colors.Red); } }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/71222.html