有没有办法全局更改 wpf 中绑定的默认行为? [英] Is there a way to globally change the default behaviors of bindings in wpf?

查看:27
本文介绍了有没有办法全局更改 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?

这可以通过 ControlTemplate 或 Style 完成吗?

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.hardcodet.net/2008/04/wpf-custom-binding-class

然后定义一些 CustomBinding 类(在构造函数中设置适当的默认值)和一个 MarkupExtension 'CustomBindingExtension'.然后用这样的东西替换 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:

Text="{CustomBinding Path=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天全站免登陆