标签:
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