In this article we will learn about asynchronous data binding using IsAsync and Delay in WPF.
Introduction
Demo
Let me demonstrate synchronous binding first.
Here is the cs file.
Demo:IsAsync
Intial state
Initially we got data in all fields except address without any delay. After a few seconds the address field has been populated in the different thread.
After 5000 milliseconds.
Delay
It is used to avoid calling downstream logic too soon for rapidly changing values. In some cases you might have several logic inside a set block of a property that is bound to a TextBox.Text property . That logic will be called when the user enters each character if UpdateSourceTrigger=PropertyChanged.
For a delay demonstration, I have commented the Thread.Sleep() in the get/set block of the address property and in the XAML we can see our address property bound with two Text Boxes. I have added one delay inside the address property that is highlighted in the image below.
Initial state
After 500 milliseconds.
Pro WPF: Windows Presentation Foundation in .NET 3.0