in Education by
How does “UpdateSourceTrigger” affect bindings?

1 Answer

0 votes
by
This is a property on a binding that controls the data flow from a target to a source and used for two-way data binding. The default mode is when the focus changes but there are many other options available.
 
Properties available with UpdateSourceTrigger
  • Default: This is the default value and it means a lost focus for most of the controls.
  • LostFocus: Value update will be on hold until the focus moves out of the control.
  • PropertyChanged: Value update will happen whenever a target property changes. It usually happen on every keystoke.
  • Explicit: Used to defer source updates until the user does it forcibly by the click of a button or so.
Default vs LostFocus
 
Default and LostFocus means the same thing for most of the controls with the exception of DataGrid. For DataGrid:
  • Lost Focus: Cell lost focus
  • Default: Row lost focus
Code
  1. <grid>  
  2.     <Grid.ColumnDefinitions>  
  3.         <ColumnDefinition Width="50*" />  
  4.         <ColumnDefinition Width="50*" />   
  5.      </Grid.ColumnDefinitions>  
  6.     <TextBlock Text="Source:" Width="auto" />  
  7.     <TextBox Name="SourceText" Width="160" Height="30" Margin="48,0,44,82" />  
  8.     <TextBlock Text="Target:" Grid.Column="1" Width="auto" />  
  9.     <TextBox Name="TargetText" Width="160" Height="30" Text="{Binding ElementName=SourceText, Path=Text,UpdateSourceTrigger=Default}" Grid.Column="1" Margin="44,0,47,82" />   
  10. </grid>  
Output
 
When the user types into the source TextBox:
 
output 
 

Related questions

0 votes
0 votes
0 votes
    What is Attached Properties and how to register it?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    What is WPF Dependency Property and how can we use?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
    What is Trigger and how many types of triggers in WPF?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    How can you explain view and view model in MVVM?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is a WPF Child Window?...
asked Apr 9, 2021 in Education by JackTerrance
...