WPF基础入门
Class5-WPF命令
1、xaml编写一个button,Command
绑定一个命令
<Grid><ButtonWidth="100"Height="40" Command="{Binding ShowCommand}"></Button>
</Grid>
2、编写一个model.cs
namespace WPF_Learn.Model
{class model_csdn{public model_csdn(){ShowCommand = new MyCommamd(show);}//注册命令,名字和xaml中一致public MyCommamd ShowCommand { get; set; } public void show(){MessageBox.Show("Show Message");}}
}
3、页面的cs文件绑定数据
public WPF_Form(){InitializeComponent();// 找到数据源 数据上下文this.DataContext = new WPF_Learn.Model.model_csdn();}
点击页面按钮: