Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove WPF Validation adornment from Label

I am using databinding and IDataErrorInfo style validation in a form. This form includes a Label control for which I don't want to show the red adornment when validation fails. Can anyone recommend a way to remove this adornment from Label controls?

like image 632
BrettRobi Avatar asked Mar 18 '10 00:03

BrettRobi


2 Answers

You can get rid of the default validation error template by assigning an empty ControlTemplate to the attached property Validation.ErrorTemplate.

<Label Content="{Binding ...}">
  <Validation.ErrorTemplate>
    <ControlTemplate />
  </Validation.ErrorTemplate>
</Label>

Hope this helps.

like image 139
Oskar Avatar answered Nov 14 '22 08:11

Oskar


You can disable validation for a Binding by disabling the relevant Validation mode. These can be one or all of ValidatesOnNotifyDataErrors, ValidatesOnDataErrors and ValidatesOnExceptions.

<Label Content="{Binding YOUR_BINDING_PROPERTY, 
                 ValidatesOnNotifyDataErrors=False,
                 ValidatesOnDataErrors=False,
                 ValidatesOnExceptions=False}" />
like image 42
FlyingFoX Avatar answered Nov 14 '22 07:11

FlyingFoX