【WPF】命令系统
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
- 上一篇:WPF 文本框添加水印效果
- 下一篇:C#学习笔记(二)