<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfTest"
mc:Ignorable="d"
Title="MainWindow" Height="" Width="">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="190,140,0,0" VerticalAlignment="Top" Width="" Height=""
Command="{Binding ButtonCom}" CommandParameter="测试数据绑定"/>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
} private ICommand _buttonCom = new ButtonCommand(); public ICommand ButtonCom
{
get
{
return _buttonCom;
} set
{
_buttonCom = value;
}
}
} public class ButtonCommand : ICommand
{
public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter)
{
return true;
} public void Execute(object parameter)
{
MessageBox.Show(parameter.ToString());
}
} }

CommandParameter就是传递的parameter

WPF Command Binding的更多相关文章

  1. A memory leak issue with WPF Command Binding

    Background In our application, we have a screen which hosts several tabs. In each tab, it contains a ...

  2. silverlight wpf DataTemplate Command binding

    <Grid x:Name="LayoutRoot" Background="White"> <CommonControl:NoapDataGr ...

  3. WPF MVVM,Prism,Command Binding

    1.添加引用Microsoft.Practices.Prism.Mvvm.dll,Microsoft.Practices.Prism.SharedInterfaces.dll: 2.新建文件夹,Vie ...

  4. WPF 杂谈——Binding表达式

    不管是定义控件还是用户控件都会用到一个功能--绑定(Binding).书面的叫法:元素绑定.意思就是让绑定的元素实现数据同步.在笔者看来WPF引入这一个功能实在是太完美了.编程更加的具体化.特别是跟M ...

  5. WPF之Binding深入探讨

    原文:http://blog.csdn.net/fwj380891124/article/details/8107646 1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在 ...

  6. MVVM Command Binding: InvokeCommandAction v.s. EventToCommand

    This gives you the ability to create a trigger on an event and bind it to an ICommand on the view mo ...

  7. WPF数据绑定Binding(二)

    WPF数据绑定Binding(二) 1.UI控件直接的数据绑定 UI对象间的绑定,也是最基本的形式,通常是将源对象Source的某个属性值绑定 (拷贝) 到目标对象Destination的某个属性上. ...

  8. WPF的Binding功能解析

    1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在存储.逻辑和界面三层之间流通,所以站在数据的角度上来看,这三层都很重要.但算法在3层中的分布是不均匀的,对于一个3层结构的 ...

  9. 【转】WPF中Binding的技巧(一)

    WPF中Binding的技巧(一)   在WPF应用的开发过程中Binding是一个非常重要的部分. 在实际开发过程中Binding的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到 ...

随机推荐

  1. MySql分类

    基础 数据类型宽度 查看字段长度 数据类型 运算符 函数 查询 插入 更新 删除 索引 自定义存储过程和函数 视图 触发器 权限管理 备份和恢复 日志 优化 复制

  2. 【log4net】配置

    第一步在 AssemblyInfo  添加如下代码 第二步:在web.config添加如下代码: <log4net> <root> <level value=" ...

  3. CSS纯样式实现箭头、对话框等形状

    在使用第三方框架bootstrap的时候,本以为其是图片实现的小箭头,后来使用开发工具查看是用CSS来实现的,现记录如下: 之前都没仔细去观注过其原理,都是拿来使用,在实现小箭头之前需要了解下CSS的 ...

  4. linux动态网络和静态网络和克隆后的网络配置

    建议设置网卡NAT模式 动态网络配置:1.一定要开启本地DHCP服务 2.在虚拟网络编辑器中选择NAT模式选中DHCP项如下图 3.ifup eth0 静态网络配置 : 注释:ifcfg-eth0部分 ...

  5. matlab2015b调用摄像头

    参考链接:http://blog.csdn.net/lyqmath/article/details/7307429 本人电脑是宏碁T5000 调用代码: % By lyqmathclc; clear ...

  6. ubuntu下ROS安装时sudo rosdep init和rosdep update的解决方法

    问题: 在ubuntu上多次安装matlab选择合适的版本来调用摄像头,终于把系统搞坏了,重装系统后,ROS无法安装,每次安装到sudo rosdep init和rosdep update报错的问题, ...

  7. VS2010 调试窗口一闪而过解决方法

    若此时进行的操作是编译(F5),可先运行程序(Ctrl+F5),若仍然一闪而过,用下面方法解决. 方法一: 1.要有头文件cstdlib,在程序最后写一句(return之前)添加:system(&qu ...

  8. phpcms v9调用多个栏目下文章的方法

    示例:{pc:get sql="SELECT * from v9_news where status=99 and catid in(6,7,8) order by id DESC" ...

  9. Cassandra 分布式集群

    1 实施Cassandra集群,并验证集群功能正常,抓图实验过程 2 为什么说对于布隆过滤器有"确定某个元素是否在某个集合中的代价和总的元素数目无关"?误判率和元素数目有关吗?为什 ...

  10. Mongodb--gridfs与分片实验

    1.放置一个大文件到gridfs,查看fs.chunks和fs.files的情况. Step1.开启一台mongod服务. ./mongod --dbpath dbs/master     登录mon ...