码迷,mamicode.com
首页 > Windows程序 > 详细

WPF MVVM,Prism,Command Binding

时间:2016-05-31 22:28:09      阅读:553      评论:0      收藏:0      [点我收藏+]

标签:

1.添加引用Microsoft.Practices.Prism.Mvvm.dll,Microsoft.Practices.Prism.SharedInterfaces.dll;

2.新建文件夹,View,ViewModel,View中添加新项FirstView.XAML(Window页面),在ViewModel中添加新项FirstViewModel.CS(类);

3.在FirstView.xaml.cs的构造函数中添加  DataContext=new FirstViewModel();

4.在FirstView页面,添加<Button Width="300" Height="100" FontSize="50" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="10" Command="{Binding BtnCommand}" Content="Click Here"/> 绑定命令;

5.在FirstViewModel.CS页面中添加

private ICommand _BtnCommand;

public ICommand BtnCommand
{
get
{
if (_BtnCommand == null)
{
_BtnCommand=new DelegateCommand<string>((obj)=>Add(10,20));
}
return _BtnCommand;
}
}

public void Add(int x, int y)
{
int z = x + y;
MessageBox.Show(z.ToString());
}

 

技术分享

WPF MVVM,Prism,Command Binding

标签:

原文地址:http://www.cnblogs.com/Fred1987/p/5547618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!