WPF MVVM,Prism,Command Binding

Posted Fred1987

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF MVVM,Prism,Command Binding相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

从PRISM开始学WPFMVVMViewModel?

从PRISM开始学WPFPrism?

从PRISM开始学WPFMVVM事件聚合器EventAggregator?

从PRISM开始学WPFPrism-Module?

wpf中mvvm的Command绑定后,如何在点击按钮的时候在viewmodel里面异步执行方法。

Prism/MVVM (MEF/WPF):从模块中公开导航 [例如菜单]