初學(xué)者 希望能通俗一點(diǎn)解析 謝謝!
代碼:
viewModel 繼承了NotificationObject 這個(gè)就是?
當(dāng)屬性值set 執(zhí)行一個(gè)方法?RaisePropertyChanged ?叫依賴屬性。
?
同理需要一個(gè)命令屬性 什么一個(gè)委托和委托對(duì)應(yīng)的方法
class MainWindowViewModel : NotificationObject
{
private double input1;
public double Input1
{
get { return input1; }
set
{
input1 = value;
this.RaisePropertyChanged("Input1");
}
}
private double input2;
public double Input2
{
get { return input2; }
set
{
input2 = value;
this.RaisePropertyChanged("Input2");
}
}
private double result;
public double Result
{
get { return result; }
set
{
result = value;
this.RaisePropertyChanged("Result");
}
}
public DelegateCommand AddCommand { get; set; }private void Add(object parameter)
{
this.Result = this.Input1 + this.Input2;
}
public MainWindowViewModel()
{
this.AddCommand = new DelegateCommand();
this.AddCommand.ExecuteAction = new Action(this.Add);
}
ICommand是定義一個(gè)命令 下面有2個(gè)方法和一個(gè)事件
class DelegateCommand : ICommand
{
public bool CanExecute(object parameter)
{
if (this.CanExecuteFunc == null)
{
return true;
}
return this.CanExecuteFunc(parameter);
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (this.ExecuteAction == null)
{
return;
}
this.ExecuteAction(parameter);
}
public Action ExecuteAction { get; set; }
public Func CanExecuteFunc { get; set; }
}
html綁定??
問題?Add是怎么和DelegateCommand關(guān)聯(lián)起來的?
上面的代碼是ok 的 。關(guān)聯(lián)后怎么就執(zhí)行了
Execute 里面的ExecuteAction ?
難以理解 求大俠和各位朋友解析下
- 5 回答
- 0 關(guān)注
- 398 瀏覽
添加回答
舉報(bào)
0/150
提交
取消