mvvm - 使用ReactiveUI连接Viewmodel和模型

标签 mvvm reactiveui

如何连接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/

相关文章:

wpf - 在 WPF MVVM 命令行为中执行后台任务的首选方法

mvvm - react 性扩展(Rx)+ MVVM =?

.net - ReactiveUi:绑定(bind)到 ReactiveAsyncCommand 的按钮在使用一次后被禁用

c# - Reactive Extensions/Reactive UI 观察集合,将其分组并显示

wpf - Unity 的嵌套数据上下文

c# - MVVM - 处理需要在 ViewModel 表示的基础模型上执行的操作

android - 搜索 Recyclerview - 当搜索为空时滚动到顶部

c# - ReactiveCommand 返回值和 View 反馈循环

wpf - ReactiveUI:无法让代码在后台线程上运行

c# - 如何在 Xamarin.Forms 中使用 ReactiveUI 只执行一次命令?