Consider the following ViewModel property:
private string _slowProperty; public string SlowProperty { get { return _slowProperty; } set { _slowProperty = value; RaisePropertyChanged("SlowProperty"); } }
What is associated with the text box, for example:
<TextBox Text="{Binding SlowProperty}" />
Now the problem is that every time the SlowProperty value changes, and this happens quite often, the text field goes and tries to get its value, which is pretty slow. However, I could alleviate the situation by using asynchronous binding, which would still waste processor cycles.
Instead, what I would like to have is something like:
<TextBlock Text="{z:DelayedSourceBinding SlowProperty}" />
Which will try to get a binding after some delay. So, for example, if SlowProperty
changed 5 times in a row, only the last text will be displayed in the text box for a short time.
I found the following project that does something similar, so in my example, I could use it like this:
<TextBox Text="{z:DelayBinding Path=SearchText}" />
The problem with it is that it only updates the target binding after the delay. The source path, however, is evaluated, and its destination is executed each time the source changes. Which in the case of SlowProperty
will still spend CPU cycles.
I tried to make my own deferred binding class, but stuck . Is there any other binder that can do something like this?
For completeness, there are 2 more projects that perform similar tasks, but none of them address the problem that I am experiencing:
DeferredBinding is a similar solution for DelayBinding. However, it is a little harder to use.
DelayedBindingTextBox - Implements delayed binding using a custom text field control.
Thanks!