ittay
ittay

Reputation: 689

why does wpf UpdateSourceTrigger fails to work

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>

Upvotes: 1

Views: 123

Answers (2)

Eibi
Eibi

Reputation: 400

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 .

Upvotes: 1

pjrki
pjrki

Reputation: 248

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.

Upvotes: 0

Related Questions