Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.1k
Why WhenAnyValue stops working after using SuppressChangeNotifications?#3830
-
I have reactive object and monitoring for its reactive properties using Show/hide repropublicclassMainViewModel:ReactiveObject{[Reactive]publicstring?Text{get;set;}[Reactive]publicboolValue{get;set;}publicReactiveCommand<Unit,Unit>Test{get;}publicMainViewModel(){this.WhenAnyValue(o=>o.Value).Subscribe(value=>Text=value.ToString());Test=ReactiveCommand.Create(()=>{usingvardispose=this.SuppressChangeNotifications();Value=true;});}} <StackPanel> <CheckBoxContent="{Binding Text}"IsChecked="{Binding Value}"/> <ButtonContent="Test"Command="{Binding Test}"/> </StackPanel> After clicking In real project there are many properties monitored in several places outside and I need to silently update them (load values without anyone noticing the changes) and I don't want to introduce |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 8 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I'm confused as to what you're finding unexpected here - you are suppressing change notifications, they shouldn't fire! |
BetaWas this translation helpful?Give feedback.
All reactions
-
I expect to see "True" text when checkbox is checked or "False" text when it's unchecked. That's not true fortwo clicks after suppression. Put 3 breakpoints: one in value setter (V), one in text setter (T), one in subscribe (S).
Why 4 and 5 step are so strange? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
You are waiting for Garbage Collection to remove the Suppression after clicking the button, as your not disposing immediately the suppression will remain active until the Garbage Collector comes along to clean up, hence the delay. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes, same. VS prompts me withIDE0063. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Okay, I will take a look at this later when I finish work. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Okay, the binding is a bool, WhenAnyValue gives change notifications so therefore this is the way it currently operates: using this code Scenario 1 - Suppression When FALSE with a suppressed TRUE change Scenario 2 - Suppression When TRUE with a suppressed TRUE change using this code Scenario 3 - Suppression When FALSE with a suppressed FALSE change Scenario 4 - Suppression When TRUE with a suppressed FALSE change |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hmm.. "no change as equal to last change" happens because the change while suppressed will cause same value to be ignored and not remembered as "last change". That make sense, thanks. Is it possible to update that "last changed" value while suppressing? My intent is to update value without triggering any As I said earlier, I don't want to introduce Show/hide code with bool flagthis.WhenAnyValue(o=>o.Value).Subscribe(value=>{if(!IgnoreValue)// suppressed changes are ignored by subscriberText=value.ToString();});Test=ReactiveCommand.Create(()=>{IgnoreValue=true;// suppress changes by setting flagValue=true;IgnoreValue=false;}); |
BetaWas this translation helpful?Give feedback.
All reactions
-
I've refactored the code with bool flag and it looks not so bad: Show/hide refactored codepublicclassMainViewModel:ReactiveObject,ISuspendable{[Reactive]publicstring?Text{get;set;}[Reactive]publicboolValue{get;set;}publicReactiveCommand<Unit,Unit>Test{get;}boolISuspendable.IsSuspended{get;set;}publicMainViewModel(){this.WhenAnyValue(o=>o.Value).Subscribe(this, value=>Text=value.ToString());Test=ReactiveCommand.Create(()=>{usingvardispose=this.Suspend();Value=true;});}}publicinterfaceISuspendable{boolIsSuspended{get;set;}}publicsealedclassSuspendableDisposeHelper:IDisposable{readonlyISuspendablesuspendable;publicSuspendableDisposeHelper(ISuspendablesuspendable){this.suspendable=suspendable;suspendable.IsSuspended=true;}publicvoidDispose()=>suspendable.IsSuspended=false;}publicstaticclassSuspendableExtensions{publicstaticIDisposableSuspend(thisISuspendablesuspendable)=>newSuspendableDisposeHelper(suspendable);publicstaticIDisposableSubscribe<T>(thisIObservable<T>source,ISuspendablesuspendable,Action<T>onNext)=>source.Subscribe(o=>{if(!suspendable.IsSuspended)onNext(o);});} There is one more parameter to pass into |
BetaWas this translation helpful?Give feedback.
