XAML代码例如以下:
相关的事件处理器代码例如以下所看到的:
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (string.IsNullOrEmpty(this.NameTextBox.Text) == true) e.CanExecute = false; else e.CanExecute = true; } private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { string name = this.NameTextBox.Text; if (e.Parameter.ToString() == "Teacher") { this.NewItemListBox.Items.Add(string.Format("New Teacher: {0}, 学而不厌,诲人不倦。", name)); } else if (e.Parameter.ToString() == "Student") { this.NewItemListBox.Items.Add(string.Format("New Student: {0},好好学习,天天向上。", name)); } }