3
votes

In my current project i'm using several textbox controls whose content is filled from objects which are coming from a database. The object uses validation to validate the correct insertion of the text.

When i want to show a validation error (i.e. the text has to many characters) i have to add some binding options to the text property like 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 whatever to change the default values of the last three options (ValidatesOnDataErrors, NotifyOnValidationError, UpdateSourceTrigger) to the values like in the code above? The Textbox controls should look like the follwing then:

<TextBox Text="{Binding Mode=TwoWay, Path=Description}" />
1

1 Answers

3
votes

Given that this is WPF (not Silverlight) I think you do have an option: a custom markup extension. Such an extension could construct and return a Binding however you like, and would result in a simple usage pattern such as:

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

For more information on implementing a custom markup extension, see here.