c# - ReactiveUI: R/W properties vs. Output Properties -
i have "close" button , expander linked in mvvm view so:
this.bindcommand(viewmodel, vm => vm.closeresults, v => v.closebutton); this.onewaybind(viewmodel, vm => vm.hasexecuted, v => v.panel.isexpanded);
if user clicks on button, expander should collapsed. in view model, have reactivecommand should take care of this:
public reactivecommand<object> closeresults { get; protected set; } = reactivecommand.create();
in view model, hasexecuted
output property supposed expand/collapse expander depending on value:
private readonly observableaspropertyhelper<bool> _hasexecuted; public bool hasexecuted => _hasexecuted.value;
so hook command button, i'm binding hasexecuted
command so:
closeresults.select(_ => false).toproperty(this, vm => vm.hasexecuted, out _hasexecuted);
this doesn't seem anything. however, if use read-write property instead , hook this:
closeresults.subscribe(_ => { hasexecuted = false; });
it works perfectly. can explain why output property doesn't work in case? isn't toproperty
extension supposed subscribe ioberservable<bool>
select(_ => false)
returning?
i'm still in middle of getting hang of this, there's obvious i'm missing.
output properties meant reflect state of other properties or observables. it's little formula write gives property output. aren't meant set them directly. see the docs this.
closeresults.select(_ => false).toproperty(this, vm => vm.hasexecuted, out _hasexecuted);
^ saying "no matter closeresults giving output, return observable returns false"
closeresults.select(_ => false).toproperty(this, vm => vm.hasexecuted, out _hasexecuted);
^ saying "take always-false observable , turn hasexecuted output property."
your read/write property more suited you're trying here.
Comments
Post a Comment