DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

Trending

  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  • Issue and Present Verifiable Credentials With Spring Boot and Android
  • Automatic Code Transformation With OpenRewrite

WPF 4.5 – Part 4 : The New Binding’s ‘Delay’ Property

By 
Jon Antoine user avatar
Jon Antoine
·
Aug. 03, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
10.9K Views

Join the DZone community and get the full member experience.

Join For Free

DelayedBinding00If you read the MSDN page on the new WPF 4.5 features, you’ll find it under the label “Automatically updating the source of a data binding“. However, it is more precise and understandable to me to say that a ‘Delay’ property has been added to the Binding markup extension!

This post is a part of the series on WPF 4.5 new features. By reading it you’ll discover the goal of this property, how to use it and some scenario where it is really useful.

What is it ?

A binding is done between two objects : the source (where the data comes from) and the target (where the data go to). For example if you bind the Text property of a TextBlock to a property “Name” of your ViewModel, the TextBlock is the target and the source is your ViewModel.

A Binding performs synchronisation between two properties. If and only if the binding is done in TwoWay mode then the target is able to update the source value (the TextBlock is able to update the ViewModel).

This synchronisation is done immediately : each change of the target value, even a tiny tiny one update the source.

Since WPF 4.5, the Binding has a new property named ‘Delay’ which defines a timespan after which the source is updated. Each update of the target value will be done only after this delay and only if none has been done since. MSDN defines it as “The amount of time to wait before updating the binding source“.

We will see later when it can be useful.

How to use it ?

As this is an added property on the Binding, you only have to define it on each Binding you create.
The delay is defined in milliseconds and the default value of ’0′ reproduce the classic behavior of a Binding.

Here is an example of a binding which sets a delay of 500 milliseconds:

<TextBlock Text="{Binding Name, Delay=500}"/>

The delay is only applied on only one direction : from the target to the source.

When to use it ?

My first though was that it is not a really useful feature but after a certain amount of time I found some scenario in which this is very useful. Yes, my brain has a Delay too!

  1. As pointed out by MSDN, there is some controls like the Slider for which there is no need to update a source value for each pixel that the Slider moves;
  2. Refering to MSDN too, you can use this on TextBox to get the typed text by “block” instead of one letter at a time;
  3. It can be useful in master/details scenarii when the change of a selection trigger some time-consuming processing on the UI thread;
  4. In the same scenario, if you launch an async works on each change, it can strt a lot of them a saturation of the thread pool (or cause too much network use, etc.);
  5. Sometime in master/details scenarii, the details view is quite complex and it takes time to render it. Then the delay can trigger this rendering only when it’s useful.

A full example

The master/detail scenarii are the one where it can be the most useful for me so I have create a demo project to reproduce it. Let’s say that we a have a list of person and the selected one’s details are displayed. We will then have an interface which looks like this :

On each change of the Selected Person, a time-consuming process is triggered on the UI thread in the setter. I simulated this by a call of Thread.Sleep :

public Person SelectedPerson
{
    get { return _selectedPerson; }
    set
    {
        _selectedPerson = value;
        //Simulate time consuming operation
        Thread.Sleep(500);
        RaisePropertyChanged("SelectedPerson");
    }
}

When the delay is not set, navigation in the list is just slow and freeze the UI on each changes. Just letting the ‘arrow down’ key makes the UI freeze too much for me.

With the delay property set to a value of 500 milliseconds, I can easily navigate in the list with the keyboard.

<ListBox ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson,Delay=500}" />

Finally, I added a button to trigger a change from the source object just to prove that the Delay works in only one direction.

The complete code source of the Demo can be found on my dropbox folder after registration.

Again, it’s a discrete addition to the WPF framework but it’s a useful one !

If you want more info on it, you can read the MSDN page of this new property.

Windows Presentation Foundation Binding (linguistics) Property (programming)

Published at DZone with permission of Jon Antoine, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!