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

  

WPF命令参数CommandParameter的更多相关文章

  1. 八,WPF 命令

    WPF命令模型 ICommand接口 WPF命令模型的核心是System.Windows.Input.ICommand接口,该接口定义了命令的工作原理,它包含了两个方法和一个事件: public in ...

  2. WPF命令

    WPF的命令是经常使用的,在MVVM中,RelayCommand更是用得非常多,但是命令的本质究竟是什么,有了事件为什么还要命令,命令与事件的区别是什么呢?MVVM里面是如何包装命令的呢?命令为什么能 ...

  3. WPF 命令的简单总结

    WPF的命令Command主要解决的问题,就是代码复用.一个很重要的应用意义,在于它将很多地方需要的调用的相同操作,以统一的方式管理,却又提供了不同的访问结果. 举个例子来说,我可能通过“点击butt ...

  4. WPF命令(Command)介绍、命令和数据绑定集成应用

    要开始使用命令,必须做三件事: 一:定义一个命令 二:定义命令的实现 三:为命令创建一个触发器 WPF中命令系统的基础是一个相对简单的ICommand的接口,代码如下: public interfac ...

  5. 【WPF学习】第三十一章 WPF命令模型

    WPF命令模型由许多可变的部分组成.总之,它们都具有如下4个重要元素: 命令:命令表示应用程序任务,并且跟踪任务是否能够被执行.然而,命令实际上不包含执行应用程序任务的代码. 命令绑定:每个命令绑定针 ...

  6. linux管道命令grep命令参数及用法详解---附使用案例|grep

    功能说明:查找文件里符合条件的字符串. 语 法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>] ...

  7. Linux xargs将输出数据流转换成命令参数

    200 ? "200px" : this.width)!important;} --> 介绍 我们可以利用管道将一个命令的“标准输出”作为另一个命令的“标准输入”:但是这里的 ...

  8. 烂泥:【转】rsync命令参数详解

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. rsync安装完毕后,我们可以通过rsync –help查看rysnc命令的使用.如下: 有关rsync的命令格式,在此我们就不多介绍了.如果有想了解的 ...

  9. linux mount命令参数及用法详解

    linux mount命令参数及用法详解 非原创,主要来自 http://www.360doc.com/content/13/0608/14/12600778_291501907.shtml. htt ...

随机推荐

  1. nginx报file not found错误

    查看错误日志 [:q2013/10/20 18:41:40 [error] 27151#0: *106117 FastCGI sent in stderr: "Primary script ...

  2. 使用junit进行Spring测试

    这几天在做SpringMVC的项目,现在总结一下在测试的时候碰到的一些问题. 以前做项目,是在较新的MyEclipse(2013)上面进行Maven开发,pom.xml 文件是直接复制的,做测试的时候 ...

  3. js常用函数收集

    在js中,可以使用typeof获取变量或函数的类型,如下: <head runat="server"> <title></title> < ...

  4. 小心C语言的定义与声明

    小心C语言的定义与声明 转自360博客 注:为便于说明问题,文中提及的变量和函数都被简化. 一.起源 DBProxy在测试过程中,发现对其执行某步管理操作后,程序有时会崩溃,但不是每次都出现. 二.G ...

  5. NOJ1008-第几天

    第几天 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte总提交 : 2701            测试通过 : 800  ...

  6. oracle 表迁移方法 (二) 约束不失效

    DB:11.2.0.3.0 在oracle 表迁移方法 (一)中,只是move了一张普通的表,如果表的字段带有主键约束呢 ? [oracle@db01 ~]$ sqlplus / as sysdba ...

  7. Postgres Basic Commands for Beginners

    Just sharing what I have learned about postgres recently. Here is a part of basic commands you may n ...

  8. AppCan移动平台开发常见问题解答

    在使用AppCan移动平台开发跨平台APP时,有开发者会遇到一些问题, 不急,跟笔者一起来聊一聊使用AppCan平台开发中常见问题的解答方法. 问1.正常是按照官网提供的4个iphone启动图尺寸来做 ...

  9. hdu 1873 看病要排队

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1873 看病要排队 Description 看病要排队这个是地球人都知道的常识.不过经过细心的0068的 ...

  10. hdu 3074 Multiply game

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3074 Minimum Inversion Number Description Tired of pl ...