前置准备包括:安装Prism, DataContext=new ViewModel();,让类继承 internal class ViewModel:BindableBase
关于按钮绑定步骤
首先前台命令的绑定需要用Command
Command="{Binding MyCommand}"
然后后台事件绑定需要三个内容
- 在类的构造函数进行初始化
MyCommand = new DelegateCommand(ExecuteMyCommand);
- 属性设置:
public ICommand MyCommand { get; private set; }
- 事件定义:
private void ExecuteMyCommand()
{
MessageBox.Show("按钮成功绑定");
}
数据绑定只有一个后台操作:
private string _textBlock1;
public string TextBlock1
{
get { return _textBlock1; }
set { SetProperty(ref _textBlock1, value); }
}