简体   繁体   English

WPF捕获文本框onBlur事件

[英]WPF Capture a Textbox onBlur event

I have a textbox in my WPF Application. 我的WPF应用程序中有一个文本框。 I am used to web development where you can capture the onBlur events with JavaScript. 我习惯于Web开发,在那里您可以使用JavaScript捕获onBlur事件。 Is this possible also in my WPF app? 我的WPF应用程序中也有可能吗?

All I am trying to do is NOT have a "Save" button, but to just update the database when they are finished modifying the text. 我要做的只是没有“保存”按钮,而只是在完成修改文本后更新数据库。

Did you read all available events descriptions? 您是否阅读了所有可用的事件描述? See: http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx 请参阅: http//msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx

I guess you are looking for LostFocus event but you should look for the one that best fits your solution. 我想您正在寻找LostFocus事件,但您应该寻找最适合您的解决方案的事件。

Why you want to do it using an event? 为什么要使用事件来做到这一点?

In WPF, when you want to update your back logic when you lose focus on a control, you usually use a Binding with UpdateSourceTrigger equal to LostFocus 在WPF中,当您想在失去对控件的关注时更新后退逻辑时,通常使用Binding,且UpdateSourceTrigger等于LostFocus

Just as example 举个例子

<TextBox Text="{Binding myBackLogicText, UpdateSourceTrigger=LostFocus}"  />

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

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