Silverlight – How to limit the value of the slider change event?

I have a slider and the value change forces a fairly strict calculation, so I want to limit it to trigger actual events, such as 50ms passing, when the user finishes sliding it.

Although I have learned some various things about Rx, it is not clear how I should use the MVVM mode to deal with this problem.

In my current MVVM method, I will The slider value is bound to my viewModel. I prefer to add the Rx throttle, which has the least impact on the existing code (at least the starting point).

I see some other threads about MVVM and Rx, I I don’t think they led me in the exact direction of my problem. I see all possible ways and don’t want to invent an attachment.

< div class="answer"> In this case, you should bind to the PropertyChanged event of the ViewModel as follows:

Observable.FromEvent (x => this.PropertyChanged += x, x => this.PropertyChanged -= x)
.Where(x => x.PropertyName == "SliderName")
.Select(_ => this.SliderName)
.Throttle(TimeSpan.FromMilliseconds(50));

Or, if you use ReactiveUI, it will look like this:

this.WhenAnyValue(x => x.SliderName)
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.DeferredScheduler);

I have For a slider, the value change forces a fairly strict calculation, so I want to limit it to trigger actual events, such as 50ms passing, when the user finishes sliding it.

Although I learned some Regarding various things about Rx, it is not clear how I should use the MVVM mode to deal with this problem.

In my current MVVM method, I bind the slider value Set to my viewModel. I prefer to add the Rx throttle, which has the least impact on the existing code (at least the starting point).

I see some other threads about MVVM and Rx, and I don’t think they cause I have the exact direction of my question. I see various possible methods and don’t want to invent an attachment.

In this case, you should tie The PropertyChanged event assigned to the ViewModel is as follows:

Observable.FromEvent(x => this.PropertyChanged += x, x => this. PropertyChanged -= x)
.Where(x => x.PropertyName == "SliderName")
.Select(_ => this.SliderName)
.Throttle(TimeSpan.FromMilliseconds(50 ));

Or, if you use ReactiveUI, it will look like this:

this.WhenAnyValue(x => x.SliderName)
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.DeferredScheduler);

Leave a Comment

Your email address will not be published.