<Window x:Class="WpfApplication1.Window29"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window29" Height="278" Width="398">
<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 HorizontalAlignment="Left" Name="textBlock1" Text="Name:" VerticalAlignment="Center" Grid.Row="0"/>
<TextBox x:Name="txtName" Margin="60,0,0,0" Grid.Row="0"></TextBox>
<Button Content="New Teacher" Grid.Row="2" Command="New" CommandParameter="Teacher"></Button>
<Button Content="New Student" Grid.Row="4" Command="New" CommandParameter="Student"></Button>
<ListBox Grid.Row="6" x:Name="lbInfos">

</ListBox>

</Grid>
<!--为窗体添加CommandBinding-->
<Window.CommandBindings>
<CommandBinding Command="New" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed">

</CommandBinding>
</Window.CommandBindings>
</Window>

----------------------------------------------------------------------------------------------------------------------------------------

public partial class Window29 : Window
{
  public Window29()
  {
  InitializeComponent();
  }

  private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  {
    if (string.IsNullOrEmpty(txtName.Text))
    {
    e.CanExecute = false;
    }
    else
    {
      e.CanExecute = true;
    }
    //路由终止,提高系统性能
    e.Handled = true;
}

private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
  {
    if (e.Parameter.ToString() == "Student")
    {
      this.lbInfos.Items.Add(string.Format("New Student:{0} 好好学习,天天向上。",txtName.Text));
    }
    else if(e.Parameter.ToString()=="Teacher")
    {
      this.lbInfos.Items.Add(string.Format("New Teacher:{0} 学而不厌,诲人不倦。", txtName.Text));
    }
    //路由终止,提高系统性能
    e.Handled = true;
  }
}

commandBinding 的命令的更多相关文章

  1. WPF 通过CommandBinding捕获命令

    RoutedCommand与业务逻辑无关,业务逻辑是通过CommandBinding来实现 using System; using System.Collections.Generic;using S ...

  2. WPF学习之深入浅出话命令

    WPF为我们准备了完善的命令系统,你可能会问:"有了路由事件为什么还需要命令系统呢?".事件的作用是发布.传播一些消息,消息传达到了接收者,事件的指令也就算完成了,至于如何响应事件 ...

  3. WPF命令

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

  4. WPF Demo19 命令、UC

    命令系统的基本元素和关系WPF命令系统的组成要素:A.命令(command):WPF命令实际上就是实习了ICommand接口的类.平时使用最多的就是RoutedCommand类.B.命令源(comma ...

  5. WPF中的命令与命令绑定(二)

    原文:WPF中的命令与命令绑定(二) WPF中的命令与命令绑定(二)                                              周银辉在WPF中,命令(Commandi ...

  6. WPF中的命令与命令绑定(一)

    原文:WPF中的命令与命令绑定(一)   WPF中的命令与命令绑定(一)                                           周银辉说到用户输入,可能我们更多地会联想到 ...

  7. WPF命令绑定 自定义命令

    WPF的命令系统是wpf中新增加的内容,在以往的winfom中并没有.为什么要增加命令这一块内容.在winform里面的没有命令只使用事件的话也可以实现程序员希望实现的功能.这个问题在很多文章中都提到 ...

  8. 命令——WPF学习之深入浅出

    WPF学习之深入浅出话命令   WPF为我们准备了完善的命令系统,你可能会问:“有了路由事件为什么还需要命令系统呢?”.事件的作用是发布.传播一些消息,消息传达到了接收者,事件的指令也就算完成了,至于 ...

  9. WPF 使用附加属性增加控件属性

    使用附加属性增加控件属性,使得这个附加属性在使用的时候没有局限性,可以在任何的控件中使用它来增加所需要的属性,使得控件的属性使用起来非常灵活 一.自定义附加属性 using System; using ...

随机推荐

  1. c语言:结果不理解

    #include <stdio.h> int main() { int a;float b; scanf("a=%d,b=%f",&a,&b); pri ...

  2. 剖析:如何用 SwitchUI 5天写一个微信 —— 聊天界面篇

    前置资源 GitHub: SwiftUI-WeChatDemo 第零章:用 SwiftUI 五天组装一个微信 - wavky - 博客园 整体结构 UI 部分代码分布如上图所示,App 的主入口类为 ...

  3. Linux上生产环境源码方式安装配置postgresql12

    1.Linux上源码方式安装postgresql12 01.准备操作系统环境 echo "192.168.1.61 tsepg61" >> /etc/hosts mou ...

  4. lucene 类介绍

    lucene中重要的类: IndexWriter:lucene中最重要的类之一,主要用于索引的创建 Analyzer(抽象类):分析器,主要用于分析文本,常用的有StandardAnalyzer分析器 ...

  5. Guava - Map

    创建Map 通常在创建map时使用new HashMap<>();的方法,guava提供了一个简洁的方法 Maps.newHashMap(); List转换Map List<Solu ...

  6. tomcat日志及logback相关日志框架

    一.重点问题整理 1.1 关于logback.xml中的路径设置问题 准备金系统的logback.xml中设置的路径是: <!-- 定义日志文件 输出位置 --> <property ...

  7. [考试总结]noip模拟20

    第五场,再挂分就没了.. 然后就没了.. 考场上一直想方法. 似乎想到了 \(T1\) 正解. 然而几个 \(k\) 的调试信息都让我迷失了自我. 然后有几句啥都没用的语句加在了上面.. 挂分... ...

  8. 第八篇 -- 对数据库mysql进行连接并压测

    参考链接:https://blog.csdn.net/laofashi2015/article/details/81296929 工具:mysql-8.0.12-winx64,apache-jmete ...

  9. Redis(6379)未授权访问

    环境搭建 打开kali终端 输入命令 wget http://download.redis.io/releases/redis-3.2.0.tar.gz tar xzf redis-3.2.0.tar ...

  10. Tomcat7+ 弱口令 && 后台getshell漏洞

    打开tomcat管理页面http://192.168.49.2:8080/manager/html,输入弱密码tomcat:tomcat,即可访问后台 先将jsp大马压缩为zip,再将zip后缀改名为 ...