How to change binding parameter default values ​​in WPF?

In my current project, I use several text field controls, the contents of which are populated from objects coming from the database. The object uses validation to verify that text is inserted correctly.

When I want to show a validation error (i.e. the text has many characters), I have to add some binding options to the text property, as in the following line:

<TextBox Text="{Binding Mode=TwoWay, Path=Description, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />

Is it possible to create a template or style or something else to change the default values ​​for the last three parameters (ValidatesOnDataErrors, NotifyOnValidationError, UpdateSourceTrigger) for values ​​similar to the above? Textbox controls should look like this:

<TextBox Text="{Binding Mode=TwoWay, Path=Description}" />
+3
source share
1 answer

Given that this is WPF (not Silverlight), I think you have the option: custom markup extension. Such an extension could build and return Bindingas you like, and lead to a simple usage pattern, for example:

<TextBox Text="{ValidatedBinding Description}"/>

For more information on implementing custom markup extensions, see here .

+3
source

Source: https://habr.com/ru/post/1769158/


All Articles