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
- <grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="50*" />
- <ColumnDefinition Width="50*" />
- </Grid.ColumnDefinitions>
- <TextBlock Text="Source:" Width="auto" />
- <TextBox Name="SourceText" Width="160" Height="30" Margin="48,0,44,82" />
- <TextBlock Text="Target:" Grid.Column="1" Width="auto" />
- <TextBox Name="TargetText" Width="160" Height="30" Text="{Binding ElementName=SourceText, Path=Text,UpdateSourceTrigger=Default}" Grid.Column="1" Margin="44,0,47,82" />
- </grid>
Output
When the user types into the source TextBox: