mvvmContext.SetBinding方法不能触发OnPropertyChanged?
winform MVVM demo中使用// Set type of POCO-ViewModel mvvmContext.ViewModelType = typeof(SumViewModel);
// Data binding for the operands
mvvmContext.SetBinding(editor1, e => e.EditValue, "Operand1");
mvvmContext.SetBinding(editor2, e => e.EditValue, "Operand2");
// Data binding for the result
mvvmContext.SetBinding(resultLabel, l => l.Text, "ResultText");
可以在改变textedit控件值的时候自动把计算结果赋给label,但我在实际测试中做不到这一点,
改变textedit控件值的时候没有任何事件被触发。
如果把SetBinding方法换成以下方式实现是可以的,
TestViewModel viewModel = mvvmContext.GetViewModel<TestViewModel>();
editor1.DataBindings.Add("EditValue", viewModel, "Operand1", true, DataSourceUpdateMode.OnPropertyChanged);
editor2.DataBindings.Add("EditValue", viewModel, "Operand2", true, DataSourceUpdateMode.OnPropertyChanged);
不知道SetBinding失效的具体原因是什么?
附上POCO viewmodel部分代码:
// using the BindableProperty attribute
public virtual int Operand1 { get; set; }
// using the BindableProperty attribute
public virtual int Operand2 { get; set; }
protected void NotifyResultAndResultTextChanged() {
this.RaisePropertyChanged(x => x.Result); // change-notification for the Result
this.RaisePropertyChanged(x => x.ResultText); // change-notification for the ResultText
}
使用fluentAPI.SetBinding替代editor1.DataBindings.Add也是可以得
页:
[1]