Is there a way to globally change the default behaviors of bindings in wpf?

前端 未结 3 1722
甜味超标
甜味超标 2020-12-10 15:09

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 b

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 16:10

    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

    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...}"

    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.

提交回复
热议问题