是否有全局更改在WPF绑定的默认行为的方法吗? [英] Is there a way to globally change the default behaviors of bindings in wpf?

查看:137
本文介绍了是否有全局更改在WPF绑定的默认行为的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法更改绑定的默认行为,所以我不需要设定'UpdateSourceTrigger =的PropertyChanged'每个,在我的情况下,文本框?

Is there a way to change the default behavior of bindings so i don't need to set 'UpdateSourceTrigger=PropertyChanged' on each, in my case, textbox?

也许这是通过控件模板或样式做了什么?

Might this be done via a ControlTemplate or Style?

推荐答案

也许是更适合来覆盖默认的绑定,您可以用这一个目的:

Maybe it's more suitable to override the defaults for your Bindings, you could use this one for that purpose:

HTTP://www.hard$c$ ct.net/2008/04/wpf-custom-binding-class

然后定义一些CustomBinding类(在构造函数中设置适当的默认值)和的MarkupExtensionCustomBindingExtension。 然后,通过这样的替换你的XAML绑定:

Then you define some CustomBinding class (setting appropriate defaults in the constructor) and a MarkupExtension 'CustomBindingExtension'. Then replace the bindings in your XAML by something like this:

文本={CustomBinding路径= XY ...}

Text="{CustomBinding Path=Xy...}"

我已经成功地尝试了绑定,设置一定的默认ValidatesOnDataError和NotifyOnValidationError类似的东西,应该在你的情况下正常工作。 现在的问题是,如果你是舒服取代所有的绑定,但你可以自动执行此任务。

I have successfully tried something similar with a binding that sets certain defaults for ValidatesOnDataError and NotifyOnValidationError, should work in your case as well. The question is if you are comfortable with replacing all your bindings, but you could automate this task.

这篇关于是否有全局更改在WPF绑定的默认行为的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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