简体   繁体   English

为什么 wpf UpdateSourceTrigger 无法工作

[英]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?为什么提供的简单代码会在每次按键时复制“源”文本而不是在 lostFocus 上?

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

What your code says is as follows:您的代码内容如下:

The first TextBox is bound to the TextBox control bellow it.第一个 TextBox 绑定到它下面的 TextBox 控件。 So the text of the first TextBox will change according to the Text value of the second TextBox.所以第一个 TextBox 的文本会根据第二个 TextBox 的 Text 值改变。

The answer is: The lostfocus is when you are changing the first TextBox.答案是:丢失焦点是在您更改第一个 TextBox 时。 When you are changing the second one, since it is bound by the first TextBox, it updates automatically on the first one.当您更改第二个时,由于它受第一个 TextBox 的约束,因此它会在第一个时自动更新。

Edit: I have run that code: If you change the first TextBox, only when you loose focus, the other TextBox will change.编辑:我已经运行了该代码:如果您更改第一个 TextBox,只有当您失去焦点时,其他 TextBox 才会更改。 If you change the second one, the first one will automatically change, just as I would expect .如果您更改第二个,第一个将自动更改,正如我所期望的

this is fairly simple.这相当简单。 UpdateSourceTrigger with LostFocus updates the binding source whenever the binding target element loses focus.每当绑定目标元素失去焦点时,带有 LostFocus 的 UpdateSourceTrigger 更新绑定 It's not working like both ways.它不像两种方式一样工作。 Bindings are working in a proper, correct way, just as expected.正如预期的那样,绑定以正确、正确的方式工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM