Reactive UI how to use WhenAny using two propertie

2019-08-12 18:12发布

I am trying to use WhenAny (Reactive UI) for the first time.

When a Identifier =="xyz" and a IsMax field get changes, want to set a local value to true in the subscribe,

   this.WhenAny(x => x.IsMax, x => x.Value)
       .Subscribe(x => 
            {
                if (Identifier == "xyz")
                {  
                   isOk = true; 
                }
            });

but is there any other way to merge Identifier condition as well?

1条回答
做自己的国王
2楼-- · 2019-08-12 19:11

I'm not familiar with ReactiveUI, but if it uses the same IObservable as Reactive Extensions, then you could do this:

   this.WhenAny(x => x.IsMax, x => x.Value)
       .Where(_ => Identifier == "xyz")
       .Subscribe(_ => 
           {
               isOk = true;
           });

Is this what you wanted?

PS.: I should have asked this in a comment, but I haven't got enough reputation yet.

查看更多
登录 后发表回答