How can i change the default values of the Binding Option in WPF?

人盡茶涼 提交于 2020-01-04 03:59:07

问题


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:


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.



来源:https://stackoverflow.com/questions/3915679/how-can-i-change-the-default-values-of-the-binding-option-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!