I am using reactiveui.
I want to run a some task based on the state of 2 properties.
How can I make the task run when sw1 is true and sw2 is false?
I tried as below but it doesn't work.
private bool Ch1SW { get; set; }
private bool Ch2SW { get; set; }
this.WhenAnyValue(x => x.Ch1SW , x => x.Ch2SW , (sw1, sw2) => (sw1, sw2))
.Where(sw => sw.sw1 == true && sw.sw2 == false)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(async x => { //some work });
The properties have to be public and you need to have the property changed mechanism implemented. If you are using reactiveui the easiest way is to add the
[Reactive]attribute over the property declaration (from theReactiveUI.Fodypackage). Then theWhenAnyValuewill return theIObservableyou can directly subscribe to and execute your function.EDIT: The
[Reactive]still requires the class to inherit fromReactiveObject