XAML代码如下:

<Window x:Class="Demo006.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="240" Width="360" WindowStyle="ToolWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="24" />
<RowDefinition Height="4" />
<RowDefinition Height="24" />
<RowDefinition Height="4" />
<RowDefinition Height="24" />
<RowDefinition Height="4" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Name:" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox Grid.Row="0" Name="NameTextBox" Margin="60,0,0,0" />
<Button Grid.Row="2" Content="New Teacher" Command="New" CommandParameter="Teacher" />
<Button Grid.Row="4" Content="New Student" Command="New" CommandParameter="Student" />
<ListBox Grid.Row="6" Name="NewItemListBox" Height="117" VerticalAlignment="Bottom" />
</Grid>
<Window.CommandBindings>
<CommandBinding Command="New"
CanExecute="CommandBinding_CanExecute"
Executed="CommandBinding_Executed" />
</Window.CommandBindings>
</Window>

相关的事件处理器代码如下所示:

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));
}
}

  

最新文章

  1. 多本地代码工作点更新到2个远端GIT仓库
  2. 使用do{ } while(0)的好处
  3. [原]通过配合ffmpeg.exe获取视频文件时长
  4. linux指令之文件的创建、查询、修改
  5. java中instanceof和getClass()的区别分析
  6. barrier()函数
  7. Error in notifier
  8. 13、主线程任务太多导致异常退出(The application may be doing too much work on its main thread)
  9. 三分--Football Goal(面积最大)
  10. js实现全屏
  11. ThinkPHP中的动态缓存(S方法)和快速缓存(F方法)(转)
  12. 在ADS上由于volatile惹得祸
  13. UWP 实现App多语言为所欲为切换
  14. Windows下基于ADS+J-Link 的ARM开发环境搭建
  15. vue element-ui 分页组件封装
  16. Socket通信例子
  17. IDEA常用快捷键总结
  18. 07-查询操作(DQL)-多表查询
  19. 【python】查找函数定义
  20. create database link

热门文章

  1. PHP实现的一分页工具类代码
  2. 【FitNess】测试框架试用
  3. API - .add()
  4. html中调用silverlight中的方法
  5. wpf的datepicker处理
  6. 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。
  7. 011--VS2013 C++ 斜角地图贴图
  8. 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw&#39;的解决办法
  9. php对象
  10. plist 读取 swift