如何连接Viewmodel并为ReactiveUI方法建模?
甚至还有ReactiveUI的方式(正常属性像this.RaiseAndSetIfChanged)吗?
问候
托比亚斯
编辑:小样本:
public class TestModel
{
public string TestName { get; set; }
}
public class TestViewModel : ReactiveObject
{
private TestModel _model;
public TestViewModel(TestModel model)
{
_model = model;
}
public TestName
{
get
{
return _model.Name;
}
set
{
//Update model value and raise PropertyChanged, but how?
}
}
}
最佳答案
public string TestName
{
get
{
return _model.TestName;
}
set
{
if (_model.TestName == value) return;
_model.TestName = value;
this.RaisePropertyChanged();
}
}
您可以将其包装在扩展方法中,该方法需要一个表达式来知道要更新哪个字段。
关于mvvm - 使用ReactiveUI连接Viewmodel和模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29176047/