Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to postpone an update to a Binding in WPF

Is there an easy way to tell a Two-way WPF data binding to wait a few milliseconds after the last change before updating the Source with the new property value?

I'm implementing a filter feature for a ListBox where I have a textbox, and I want to filter the content of the ListBox according to what I type. I'm using data binding to connect the pieces together. Filtering the list can be quite time consuming, so I don't want to do it after every character that is typed: hence my request.

I have been using Paul Stovell's DelayBinding Extension (his site's down at the moment, so I can't link to it). However, I suspect that it is the cause of a memory leak in my applicataion (caused by it not removing event handlers).

Does anybody else have any other ideas?

like image 776
Samuel Jack Avatar asked Jan 29 '09 13:01

Samuel Jack


1 Answers

I'm also a few years late, but if you're using WPF 4.5+ there is now an property exactly for this purpose, it's called Delay.

Description

The amount of time, in milliseconds, to wait before updating the binding source.

Example usage

<TextBlock Text="{Binding Name, Delay=500}"/>
like image 118
João Portela Avatar answered Oct 19 '22 07:10

João Portela