Tobi
Tobi

Reputation: 183

Using ReactiveUI to wire up Viewmodel and model

How do I wire up Viewmodel and model the ReactiveUI way? Is there even a ReactiveUI way (like this.RaiseAndSetIfChanged for normal properties)?

Regards Tobias

Edit: small Sample:

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?
        }
    }
}

Upvotes: 1

Views: 777

Answers (1)

Michal Ciechan
Michal Ciechan

Reputation: 13888

public string TestName
{
    get
    {
        return _model.TestName;
    }
    set
    {
        if (_model.TestName == value) return;
        _model.TestName = value;
        this.RaisePropertyChanged();
    }
}

You could wrap this up in an extension method that takes an expression to know which field to update.

Upvotes: 1

Related Questions