WPF Command Binding
<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的更多相关文章
- 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 ...
- silverlight wpf DataTemplate Command binding
<Grid x:Name="LayoutRoot" Background="White"> <CommonControl:NoapDataGr ...
- WPF MVVM,Prism,Command Binding
1.添加引用Microsoft.Practices.Prism.Mvvm.dll,Microsoft.Practices.Prism.SharedInterfaces.dll: 2.新建文件夹,Vie ...
- WPF 杂谈——Binding表达式
不管是定义控件还是用户控件都会用到一个功能--绑定(Binding).书面的叫法:元素绑定.意思就是让绑定的元素实现数据同步.在笔者看来WPF引入这一个功能实在是太完美了.编程更加的具体化.特别是跟M ...
- WPF之Binding深入探讨
原文:http://blog.csdn.net/fwj380891124/article/details/8107646 1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在 ...
- 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 ...
- WPF数据绑定Binding(二)
WPF数据绑定Binding(二) 1.UI控件直接的数据绑定 UI对象间的绑定,也是最基本的形式,通常是将源对象Source的某个属性值绑定 (拷贝) 到目标对象Destination的某个属性上. ...
- WPF的Binding功能解析
1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在存储.逻辑和界面三层之间流通,所以站在数据的角度上来看,这三层都很重要.但算法在3层中的分布是不均匀的,对于一个3层结构的 ...
- 【转】WPF中Binding的技巧(一)
WPF中Binding的技巧(一) 在WPF应用的开发过程中Binding是一个非常重要的部分. 在实际开发过程中Binding的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到 ...
随机推荐
- 读书笔记——数据库的ADO开发总结
基本上是对 ADO+开发指南.pdf 的摘抄和总结,以及个人心得. 文章末尾有<ADO+开发指南.pdf>的资源下载,附带个人批注. --------------------------- ...
- 常用HTML正则
<?php //HTML a连接正则 $str = ''; $isMatched = preg_match('/<a.*?[^<]>.*?<\/a>/', $str ...
- Java学习总结:飘逸的字符串
Java学习:飘逸的字符串 前言 相信不管我们运用Java语言来开发项目还是进行数据分析处理,都要运用到和字符串相关的处理方法.这个社会处处有着和字符串相关的影子:日志.文档.书籍等.既然我们离不开字 ...
- cocos2d-x之初试内存管理机制
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...
- JavaScript日期组件的实现
旅游频道的开发中需要定义各种日期组件,有的是基本的日期选择, 这个基本日期只包含如下功能 左右翻(月) 点击天回填到输入域 点击“今天”,回填今天的日期到输入域 点击“关闭”,日期控件关闭 有的同时显 ...
- Centos7 搭建hadoop2.6 HA
用户配置: User :root Password:toor 2.创建新用户 student Pwd: student 3.安装virtualbox的增强工具软件 4.系统默认安装的是openjdk ...
- java charset detector
https://code.google.com/p/juniversalchardet/downloads/list java移植mozilla的编码自动检测库(源码为c++),准确率高. 通过svn ...
- ZOJ 2674 Strange Limit
欧拉函数. #include<iostream> #include<stdio.h> #include<string.h> #include<algorith ...
- Redis 一二事 - 在spring中使用jedis 连接调试单机redis以及集群redis
Redis真是好,其中的键值用起来真心强大啊有木有, 之前的文章讲过搭建了redis集群 那么咋们该如何调用单机版的redis以及集群版的redis来使用缓存服务呢? 先讲讲单机版的,单机版redis ...
- java8-4 多态的练习以及题目
1./* 多态练习:猫狗案例*/ class Animal { public void eat(){ System.out.println("吃饭"); } } class Dog ...