问题描述
有没有办法更改绑定的默认行为,所以我不需要设定'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 ...}
我已经成功地尝试了绑定,设置一定的默认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绑定的默认行为的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!