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的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到 ...
随机推荐
- WP开发-Toolkit组件 列表采集器(ListPicker)的使用
列表采集器ListPicker在作用上与html中的<select/>标签一样 都是提供多选一功能,区别在于ListPicker可以自定义下拉状态和非下拉状态的样式. 1.模板设置 Lis ...
- C++基础——子类转父类转子类 (派生类转基类转派生类)
==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...
- APP原型设计工具,哪家强?转自知乎
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:李志超 链接:http://www.zhihu.com/question/20403141/answer/25329730 ...
- SQLAlchemy 中文文档翻译计划
SQLAlchemy 中文文档翻译计划已启动. Python 文档协作翻译小组人手紧缺,有兴趣的朋友可以加入我们,完全公益性质.交流群:467338606. 希望大家能够勇敢地去翻译和改进翻译.虽然我 ...
- 手工搭建Openvpn
环境: CentOS 6.4 (final) x86_x64 gcc-4.4.7-16.el6.x86_64 gcc-c++-4.4.7-16.el6.x86_64 lzo-2.03-3.1.e16_ ...
- js动态切换图片
<script language =javascript > $(function () { initAds(); }); function initAds() { var curInde ...
- LINUX 用户’nobody’
1>Windows系统在安装后会自动建立一些用户帐户,在Linux系统中同样有一些用户帐户是在系统安装后就有的,就像Windows系统中的内置帐户一样. 2>它们是用来完成特定任务的,比如 ...
- CORDIC原理与FPGA实现(1)
CORDIC算法的来历与用途大家网上随处可以见到,这里写 一下自己的理解. 将P(x,y)旋转角度a得到新的坐标P’(x’,y’).这里的坐标变换为: x’= x cos(a) – y sin(a) ...
- 边工作边刷题:70天一遍leetcode: day 89-1
Smallest Rectangle Enclosing Black Pixels 要点:记题:这题有两个限制条件:所有black pixel是连通的(所以可以用binary search)以及给了一 ...
- poj1274 The Perfect Stall (二分最大匹配)
Description Farmer John completed his new barn just last week, complete with all the latest milking ...