亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

wpf MVVM疑問 求幫忙解析 謝謝!

wpf MVVM疑問 求幫忙解析 謝謝!

眼眸繁星 2018-12-06 13:12:40
初學者 希望能通俗一點解析 謝謝! 代碼: 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 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

this.AddCommand = new DelegateCommand(); this.AddCommand.ExecuteAction = new Action(this.Add); 就是這樣關聯的啊兄弟
查看完整回答
反對 回復 2018-12-09
?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

我后面明白了 調試
查看完整回答
反對 回復 2018-12-09
?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

首先要理解DataContext屬性和INotifyPropertyChanged接口的原理。直接接觸MVVM肯定是不行的。
查看完整回答
反對 回復 2018-12-09
?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

你說的對
查看完整回答
反對 回復 2018-12-09
  • 5 回答
  • 0 關注
  • 400 瀏覽

添加回答

舉報

0/150
提交
取消