Delay In Data Bindings WPF

There is an important concept provided in WPF, which is Data binding. This allows you to wire-up UI controls to a business model in Application. When a binding is established and the data or your business model have some changes, then it reflects the updates automatically to the UI elements and vice versa which totally depends on the type of binding used in XAML.

Types of Binding support by WPF

  1. OneWay
  2. TwoWay
  3. OneWayToSource
  4. OneTime

The Data binding is done between two objects, the source (where the value comes from) and the target (where the value goes to). This performs synchronization between two properties. If and only if the binding is done in TwoWay mode then the target is able to update the source value

Delay in Data Bindings

This reflection is done immediately on each change of the target value, even a tiny change too. So you wouldn't want to raise an event or send update notifications for every little change, you just want to update this only after a delay or timespan. Then you should use the Delay keyword in Binding markup extension (XAML).

  1. <StackPanel>  
  2.          <Slider x:Name="Slider"  
  3.                  Minimum="0" Maximum="100"  
  4.                  Margin="10 40 10 20 " Height="25"  
  5.                  Value="{Binding ElementName=SliderValue,Path=Text, Delay=1000, Mode=TwoWay}" />  
  6.          <TextBox x:Name="SliderValue" Text="50" TextAlignment="Center" HorizontalAlignment="Center"  
  7.                   Width="200" Height="30" FontSize="20" />  
  8.   
  9.      </StackPanel>  

Here, I have set a value of delay property as 1000 milliseconds, Due to this, it performs a 1 second delay in data binding reflection.