简体   繁体   English

WPF - 在选项卡更改之前在选项卡中的当前活动元素上触发“LostFocus”

[英]WPF - Trigger "LostFocus" on currently active element in Tab before Tab Change

I have a TabControl, and each TabItem has multiple, data-bound textboxes.我有一个 TabControl,每个 TabItem 都有多个数据绑定文本框。 When I edit an text in one box, and the switch the tab directly (without leaving the textbox), the change is lost.当我在一个框中编辑文本并直接切换选项卡(不离开文本框)时,更改丢失。 Apparently, the "LostFocus" Event is not triggered when changing the tab, so the new value is not written to the bound property.显然,更改选项卡时不会触发“LostFocus”事件,因此新值不会写入绑定属性。

How can I trigger the "LostFocus" on the currently active (or all) elements in the active tab before changing over to the new tab?在切换到新选项卡之前,如何在活动选项卡中的当前活动(或所有)元素上触发“LostFocus”?

I could surely do an override and call the event manually on all elements, but that would be quite unhandy because one has to update that list every time a field is added.我当然可以在所有元素上进行覆盖并手动调用事件,但这会非常不方便,因为每次添加字段时都必须更新该列表。

Is there some way to do it automatically?有什么办法可以自动完成吗?

使用UpdateSourceTrigger.PropertyChanged而不是LostFocus并将绑定Delay属性设置为您选择的间隔。

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

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