EndEdit中相当于在WPF [英] EndEdit equivalent in WPF

查看:131
本文介绍了EndEdit中相当于在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF窗口,其中包含一个文本框。我已经实现了上CRTL-S,节省的窗口的内容执行一个命令。我的问题是,如果文本框是主动控制,而我最近编辑在文本框中的文本,最新的变化在文本框中不COMMITED。我需要标签出文本框来获得改变的。

I have a WPF Window that contains a TextBox. I have implemented a Command that executes on Crtl-S that saves the contents of the window. My problem is that if the textbox is the active control, and I have newly edited text in the textbox, the latest changes in the textbox are not commited. I need to tab out of the textbox to get the changes.

在的WinForms,我通常称之为EndEdit中的形式,并且所有挂起的更改会得到COMMITED。另一种方法是使用onPropertyChange结合,而不是onValidation,但我宁愿不这样做。

In WinForms, I would typically call EndEdit on the form, and all pending changes would get commited. Another alternative is using onPropertyChange binding rather than onValidation, but I would rather not do this.

什么是相当于EndEdit中的WPF,或者是在这种情形下使用该模式?

What is the WPF equivalent to EndEdit, or what is the pattern to use in this type of scenario?

谢谢

推荐答案

要避免需要到标签走的问题,你可以简单地改变你的控件的绑定UpdateSourceTrigger财产。请尝试以下操作:

To avoid the issue of needing to tab away, you could simply change the UpdateSourceTrigger property of your controls' binding. Try the following:

<TextBox.Text>
    <Binding Path="MyProperty" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>

这告诉WPF每当Text属性更改为更新的支持对象。通过这种方式,你不必担心跳格了。希望这有助于!

This tells WPF to update the backing object whenever the Text property is changed. This way, you don't need to worry about tabbing away. Hope this helps!

编辑:

有以下的SO问题接受的答案提供了一种自动运行的验证规则的页面。你可以修改它来调用UpdateSource()上的所有BindingEx pression对象来代替。

The accepted answer for the following SO question provides a way to automatically run validation rules for a page. You could modify it to call UpdateSource() on all BindingExpression objects instead.

<一个href="http://stackoverflow.com/questions/127477/detecting-wpf-validation-errors">Link

这篇关于EndEdit中相当于在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆