Remove WPF Validation adornment from Label
Asked Answered
O

2

5

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?

Obelize answered 18/3, 2010 at 0:58 Comment(1)
Can you post the xaml for the relevant part of your form?Arian
S
10

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.

Subteen answered 18/3, 2010 at 8:19 Comment(1)
Perfect and simple. Thanks Oskar.Obelize
C
3

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}" />
Complication answered 17/4, 2019 at 12:29 Comment(1)
I had a similar problem; your answer fixed it.Crumhorn

© 2022 - 2024 — McMap. All rights reserved.