Custom UpdateSourceTrigger Delayed?

I am looking to create a custom version of UpdateSourceTrigger that I can use with my binding. I don't know if this is possible, or instead I will need to create my own custom binding class. I am looking, instead of LostFocus or PropertyChanged, for something where it will update the source after a certain period.

I found this one , but I don’t know if there is a better way (one of the comments mentioned some memory leaks during implementation),

Any ideas?

+4
source share
3 answers

I would not do this at the anchor level, but would instead demonstrate this in my view model. When the property changes, restart DispatcherTimer. When the timer expires, start your logic. It's simple.

+5
source

I just noticed that WPF 4.5 has a Delay property, see more information at this link

http://www.shujaat.net/2011/12/wpf-45-developers-preview-delay-binding.html

+11
source

This can be easily implemented using the Reactive Extensions Throttle () method in combination with the observed property.

public class ObservablePropertyBacking<T> : IObservable<T> { private readonly Subject<T> _innerObservable = new Subject<T>(); private T _value; public T Value { get { return _value; } set { _value = value; _innerObservable.OnNext(value); } } #region IObservable<T> Members public IDisposable Subscribe(IObserver<T> observer) { return _innerObservable .DistinctUntilChanged() .AsObservable() .Subscribe(observer); } #endregion } 

Used as follows:

 // wire query observable var queryActual = new ObservablePropertyBacking<string>(); queryActual.Throttle(TimeSpan.FromMilliseconds(300)).Subscribe(DoSearch); 

Implementation Property:

 string query; public string Query { get { return query; } set { queryActual.Value = value; } } 
0
source

Source: https://habr.com/ru/post/1379690/


All Articles