views:

41

answers:

1

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}" />
A: 

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.

HTH,
Kent

Kent Boogaart
If you return a binding from a markup extension it doesn't behave as expected but you can inherit from Binding directly and set the properties in the constructor.
Kris
That was just the help i needed. It works like a charm. I created a new class and had it inherited from Binding and now it works. Thank you so much. :)
Bastian