Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 862
Cinaird Avatar asked Nov 02 '10 10:11

Cinaird


2 Answers

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.

like image 170
Simon D. Avatar answered Oct 19 '22 23:10

Simon D.


No. This behavior is handled by the DefaultUpdateSourceTrigger of the FrameworkPropertyMetadata class, which is passed when registering a DependencyProperty. It is possible to override this in an inherited class of TextBox and per binding, but not for every TextBox in the application.

like image 43
Pieter van Ginkel Avatar answered Oct 19 '22 22:10

Pieter van Ginkel