WPF命令参数CommandParameter
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的更多相关文章
- 八,WPF 命令
WPF命令模型 ICommand接口 WPF命令模型的核心是System.Windows.Input.ICommand接口,该接口定义了命令的工作原理,它包含了两个方法和一个事件: public in ...
- WPF命令
WPF的命令是经常使用的,在MVVM中,RelayCommand更是用得非常多,但是命令的本质究竟是什么,有了事件为什么还要命令,命令与事件的区别是什么呢?MVVM里面是如何包装命令的呢?命令为什么能 ...
- WPF 命令的简单总结
WPF的命令Command主要解决的问题,就是代码复用.一个很重要的应用意义,在于它将很多地方需要的调用的相同操作,以统一的方式管理,却又提供了不同的访问结果. 举个例子来说,我可能通过“点击butt ...
- WPF命令(Command)介绍、命令和数据绑定集成应用
要开始使用命令,必须做三件事: 一:定义一个命令 二:定义命令的实现 三:为命令创建一个触发器 WPF中命令系统的基础是一个相对简单的ICommand的接口,代码如下: public interfac ...
- 【WPF学习】第三十一章 WPF命令模型
WPF命令模型由许多可变的部分组成.总之,它们都具有如下4个重要元素: 命令:命令表示应用程序任务,并且跟踪任务是否能够被执行.然而,命令实际上不包含执行应用程序任务的代码. 命令绑定:每个命令绑定针 ...
- linux管道命令grep命令参数及用法详解---附使用案例|grep
功能说明:查找文件里符合条件的字符串. 语 法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>] ...
- Linux xargs将输出数据流转换成命令参数
200 ? "200px" : this.width)!important;} --> 介绍 我们可以利用管道将一个命令的“标准输出”作为另一个命令的“标准输入”:但是这里的 ...
- 烂泥:【转】rsync命令参数详解
本文由秀依林枫提供友情赞助,首发于烂泥行天下. rsync安装完毕后,我们可以通过rsync –help查看rysnc命令的使用.如下: 有关rsync的命令格式,在此我们就不多介绍了.如果有想了解的 ...
- linux mount命令参数及用法详解
linux mount命令参数及用法详解 非原创,主要来自 http://www.360doc.com/content/13/0608/14/12600778_291501907.shtml. htt ...
随机推荐
- php使用swoole实现一个简单的多人在线聊天群发
聊天逻辑的好多细节没有实现,只实现群发. php代码: $serv = new swoole_websocket_server("127.0.0.1",3999); //服务的基本 ...
- windows7安装IE11点击图标没反应
可以通过修改 Windows 注册表的方式解决: Win+R 打开“运行”后输入 regedit 打开 注册表编辑器 打开注册表编辑器(regedit)以后,找到注册表项HKEY_CURRENT_US ...
- Python os模块常用部分功能
os.sep 可以取代操作系统特定的路径分割符. os.name字符串指示你正在使用的平台.比如对于Windows,它是'nt',而对于Linux/Unix用户,它是'posix'. os.getcw ...
- java 复习
整型: byte 1 short 2 int 4 long 80b1001 1_233_32 1341414141414Ljava 没有无符号类型浮点型:float 4 double 812.2f 无 ...
- 浅谈Objective-C编译器指令
------<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS ...
- vim代码补全-spf13,YouCompleteMe
vim代码补全 现在的图形界面的IDE(Integrated Development Environment)一般具有语法高亮,语法检查,自动补全功能,大大提高了编程的效率. vim作为文本编辑器其强 ...
- 通过java反射实现简单的关于MongoDB的对象关系映射(ORM).
通过阅读MongoDB 3.2.1的官方文档中关于java 编程发现最新的文档并没有实现对对象到Document的映射,所以自己有了利用反射实现简单的关系映射. 1.定义抽象类:AbstractMo ...
- nodejs for centos配置
mongodb http://www.cnblogs.com/zhoulf/archive/2013/01/31/2887439.html nodejs http://zhaohe162.blog.1 ...
- [转]tftp在put上传的时候显示File not found的解决办法
[转]tftp在put上传的时候显示File not found的解决办法 http://blog.163.com/pengcz%40126/blog/static/35908607201182433 ...
- urllib3 ConnectionPools
A connection pool is a container for a collection of connections to a specific host.If you need to m ...