why does wpf UpdateSourceTrigger fails to work

90 Views Asked by At

Why does the simple provided code, copies the "source" text on each key press and not on lostFocus?

<StackPanel>
    <TextBox Text="{Binding Text, ElementName=source, UpdateSourceTrigger=LostFocus}"/>
    <TextBox x:Name="source"/>
</StackPanel>
2

There are 2 best solutions below

0
Eibi On BEST ANSWER

What your code says is as follows:

The first TextBox is bound to the TextBox control bellow it. So the text of the first TextBox will change according to the Text value of the second TextBox.

The answer is: The lostfocus is when you are changing the first TextBox. When you are changing the second one, since it is bound by the first TextBox, it updates automatically on the first one.

Edit: I have run that code: If you change the first TextBox, only when you loose focus, the other TextBox will change. If you change the second one, the first one will automatically change, just as I would expect .

0
pjrki On

this is fairly simple. UpdateSourceTrigger with LostFocus updates the binding source whenever the binding target element loses focus. It's not working like both ways. Bindings are working in a proper, correct way, just as expected.