ReactiveUI How to use WhenAnyObservable correctly

I am trying to use WhenAnyObservable for the first time.

When the number is ReactiveList Count == 0 and the length of tipText is> 0, I want to set the local value to true in the subscription, or vice versa.

this.ViewModel.WhenAnyObservable( x => x.AutoCompleteItems.CountChanged, x => x.ObservableForProperty(y => y.TipText), (countChanged, tipText) => countChanged == 0 && tipText.Length > 0); 

I have problems with work.

Is there any trick I have to do, or should I use one of the other WhenAny commands?

+7
wpf reactiveui
source share
2 answers

You have the right idea, but WhenAnyObservable does not return elements until it has an initial element for both sides if you use> 1 Observables. Therefore, you probably want to:

 this.ViewModel.WhenAnyObservable( x => x.AutoCompleteItems.CountChanged.StartWith(0), x => x.WhenAnyValue(y => y.TipText), (countChanged, tipText) => countChanged == 0 && tipText.Length > 0); 
+4
source share

When trying to use WhenAnyObservable, an index error appears. I ended up using

 Observable.CombineLatest( SomeItems.Changed.Select(x => true), this.WhenAnyValue(y => y.SomeBoolProperty), (b,g) => b && g) 
0
source share

All Articles