The Wayback Machine - https://web.archive.org/web/20200114062954/https://github.com/runceel/ReactiveProperty
Skip to content
ReactiveProperty provides MVVM and asynchronous support features under Reactive Extensions. Target framework is .NET Standard 2.0.
C# HTML
Branch: master
Clone or download
Latest commit 4deaa69 Nov 16, 2019

README.md

Japanese

ReactiveProperty

ReactiveProperty provides MVVM and asynchronous support features under Reactive Extensions. Target framework is .NET Standard 2.0.

ReactiveProperty overview

ReactiveProperty is very powful and simple library.

Delay and Select

This sample app's ViewModel code is as below:

public class MainPageViewModel
{
    public ReactiveProperty<string> Input { get; }
    public ReadOnlyReactiveProperty<string> Output { get; }
    public MainPageViewModel()
    {
        Input = new ReactiveProperty<string>("");
        Output = Input
            .Delay(TimeSpan.FromSeconds(1))
            .Select(x => x.ToUpper())
            .ToReadOnlyReactiveProperty();
    }
}

It's LINQ and Rx magic.

All steps are written getting started section in the ReactiveProperty documentation.

This library's concept is "Fun programing". ViewModel code which using ReactiveProperty is very simple.

ViewModel's popular implementation is as below:

public class AViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string _name;
    public string Name
    {
        get => _name;
        set
        {
            _name = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Name)));

            // Update a command status
            DoSomethingCommand.RaiseCanExecuteChanged();
        }
    }

    private string _memo;
    public string Memo
    {
        get => _memo;
        set
        {
            _memo = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Memo)));

            // Update a command status
            DoSomethingCommand.RaiseCanExecuteChanged();
        }
    }

    // DelegateCommand is plane ICommand implementation.
    public DelegateCommand DoSomethingCommand { get; }

    public AViewModel()
    {
        DoSomethingCommand = new DelegateCommand(
            () => { ... },
            () => !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Memo)
        );
    }
}

Binding code is as below:

<TextBlock Text="{Binding Name}">
<TextBlock Text="{Binding Memo}">

ViewModel's implementation using ReactiveProperty is as below:

public class AViewModel
{
    public ReactiveProperty<string> Name { get; }
    public ReactiveProperty<string> Memo { get; }
    public ReactiveCommand DoSomethingCommand { get; }

    public AViewModel()
    {
        Name = new ReactiveProperty<string>()
            .SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
        Memo = new ReactiveProperty<string>()
            .SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
        DoSomethingCommand = new[]
            {
                Name.ObserveHasErrors,
                Memo.ObserveHasErrors,
            }
            .CombineLatestValuesAreAllFalse()
            .ToReactiveCommand()
            .WithSubscribe(() => { ... });
    }
}

Binding code is as below:

<TextBlock Text="{Binding Name.Value}">
<TextBlock Text="{Binding Memo.Value}">

It's very simple.

ReactiveProperty doesn't provide base class by ViewModel. It's means that ReactiveProperty can use together the another MVVM library like Prism, MVVMLight, etc...

Documentation

ReactiveProperty documentation

NuGet

ReactiveProperty

Support

I'm not watching Stackoverflow and other forums to support ReactiveProperty, so please feel free ask to question at Github issues. I'm available Japanese(1st language) and English(2nd language).

If questions became huge numbers, then I would separate posting place about feature requests, issues, questions.

Author info

Yoshifumi Kawai a.k.a. @neuecc is software developer in Tokyo, Japan. Awarded Microsoft MVP for Visual Studio and Development Technologies since April, 2011. He is an original owner of ReactiveProperty.

Takaaki Suzuki a.k.a. @xin9le software devleoper in Tokyo, Japan. Awarded Microsoft MVP for Visual Studio and Development Technologies since July, 2012.

Kazuki Ota a.k.a. @okazuki software developer in Tokyo, Japan. Awarded Microsoft MVP for Windows Development since July 2011 to Feb 2017. Now, working at Microsoft Japan.

You can’t perform that action at this time.