以下の内容はhttps://blog.okazuki.jp/entry/2015/10/23/220017より取得しました。


複数のプロパティを監視してReactivePropertyの値を更新する

こういう場合は2つのIObservableをCombineLatestで合成してからReactivePropertyにしてしまえばお手軽です。

using Reactive.Bindings;
using System.Reactive.Linq;

namespace MultiValueApp
{
    class MainWindowViewModel
    {
        public ReactiveProperty<int> Lhs { get; }
        public ReactiveProperty<int> Rhs { get; }
        public ReadOnlyReactiveProperty<int> Answer { get; }

        public MainWindowViewModel()
        {
            this.Lhs = new ReactiveProperty<int>(0);
            this.Rhs = new ReactiveProperty<int>(0);
            this.Answer = this.Lhs.CombineLatest(this.Rhs, (x, y) => x + y)
                .ToReadOnlyReactiveProperty();
        }
    }
}

この例では、監視元はReactivePropertyですが通常のINotifyPropertyChangedを実装したクラスはObservePropertyでIObservable化できるので、そいつをCombineLatestしてやればOKです。




以上の内容はhttps://blog.okazuki.jp/entry/2015/10/23/220017より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14