using System.Windows;namespace TestOfCommandParameter{ ////// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void New_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) { if (string.IsNullOrEmpty(this.newTextBox.Text)) { e.CanExecute = false; } else { e.CanExecute = true; } } private void New_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { string name = this.newTextBox.Text; if (e.Parameter.ToString()=="Teacher") { this.listBoxNewItems.Items.Add(string.Format("New Teacher:{0},学而不厌,诲人不倦。", name)); } if (e.Parameter.ToString() == "Student") { this.listBoxNewItems.Items.Add(string.Format("New Student:{0},好好学习,天天向上。", name)); } } }}