使用 ReactiveUI 连接 Viewmodel 和模型

Using ReactiveUI to wire up Viewmodel and model

如何连接 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();
    }
}

您可以将其包装在一个扩展方法中,该方法采用一个表达式来知道要更新哪个字段。