Currently, I’m creating textboxes and specifying ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True every time I create a binding:
<TextBox Width="150" Text="{Binding Expander1Name, ElementName=Window,
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
ValidatesOnExceptions=True, ValidatesOnDataErrors=True,
NotifyOnValidationError=True}" Background="#FFF5EECC"></TextBox>
I would like to set ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True with a global XAML setter.
Can anyone here give a definitive answer whether it is possible to do, if not – why, if yes – how?
Not possible in the way you describe, since these properties are present on the
Bindinginstances within theDependencyObjects rather than being exposed as properties on theDependencyObjects themselves. It is not possible to create aStylethat targetsBindings.That said, there are a couple of ways you could work around this:
Bindingand sets whatever defaults you want. You would then use that class everywhere you’ve currently usedBinding.Bindings within the object to which it is attached and sets the defaults you want.The first option would be preferable to me, since the second could have unforeseen consequences (what if there’s a binding where you don’t want it to take on the defaults?). The second option would also be much slower, since it would need to dynamically search through all dependency properties of the item to which it is attached.