初學者 希望能通俗一點解析 謝謝!
代碼:
viewModel 繼承了NotificationObject 這個就是?
當屬性值set 執行一個方法?RaisePropertyChanged ?叫依賴屬性。
?
同理需要一個命令屬性 什么一個委托和委托對應的方法
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是定義一個命令 下面有2個方法和一個事件
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關聯起來的?
上面的代碼是ok 的 。關聯后怎么就執行了
Execute 里面的ExecuteAction ?
難以理解 求大俠和各位朋友解析下
- 5 回答
- 0 關注
- 400 瀏覽
添加回答
舉報
0/150
提交
取消