When using databinding in WPF, if you set Mode
property to TwoWay
, you can control the moment when the source property will be updated by setting UpdateSourceTrigger
property. That scenario is possible for target -> source update stream. But how you can control same thing for source -> target update stream? I cannot find equivalent property.
For example, lets say I have two textboxes on my window, and I want to bind Text properties of both textboxes. XAML may look like this:
<TextBox
Name="txt1"
Text="{Binding ElementName=txt2, Path=Text, Mode=TwoWay,
UpdateSourceTrigger=LostFocus}"
/>
<TextBox
Name="txt2"
/>
When user enters text in txt1
TextBox, Text
property of txt2
Textbox will be updated as Text
property changes, just if I had implemented TextChanged event on txt1
.
However, when user enters text in txt2
TextBox, Text
property of txt1
Textbox will be updated after txt2
TextBox looses focus because UpdateSourceTrigger
property is set to LostFocus
, just if I had implemented LostFocus event.
Is there possibility in WPF databinding to update target property after source property control looses focus? In our example: what should be done to XAML code above, so Text
property of txt2
TextBox would be updated only after txt1
TextBox loose focus, and not after its Text property changes?
Thanks!