Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

When a WPF validation error is not visible, first check whether the binding recorded an error and then check how the control presents it. An error can exist in Validation.Errors even when the user cannot read its message. For property validation, IDataErrorInfo is a straightforward synchronous option; INotifyDataErrorInfo offers a notification-based contract with more flexibility. Neither interface, by itself, guarantees that an explanation appears as readable text.

Why WPF validation errors may not appear as messages

Validation and presentation are separate parts of the WPF binding experience. A binding rule can detect invalid data and set Validation.HasError on the bound element, while the control’s template determines what the person using the app actually sees. Microsoft documents that the default ErrorTemplate draws a red border in the adorner layer; that visual cue does not necessarily show the error explanation as text. Microsoft’s WPF data-binding overview covers the validation state and default template. An archived Microsoft article also notes that the associated error message is not displayed by default: Input Validation: Enforcing Complex Business Data Rules with WPF.

That distinction gives you a useful first question: is there no validation error, or is there an error that the current UI does not explain?

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose the binding before changing the error display

  1. Confirm the binding source and path. Check the control’s effective DataContext, or its explicit Source, and make sure it is the object implementing the validation interface. Confirm the binding Path names the property you expect. A correct validation implementation will not help if the binding points somewhere else.
  2. Check the interface-specific binding option. For IDataErrorInfo, set ValidatesOnDataErrors="True" or add a DataErrorValidationRule. For INotifyDataErrorInfo, check that ValidatesOnNotifyDataErrors has not been disabled; its documented default is true. See Microsoft’s API documentation for ValidatesOnDataErrors and ValidatesOnNotifyDataErrors.
  3. Verify that the source returns or raises an error. With IDataErrorInfo, the indexer must return a nonempty message for the bound property name. With INotifyDataErrorInfo, verify that the implementation exposes the expected errors and sends the required notifications when they change. Microsoft’s WPF guide walks through implementing validation on custom objects: How to: Implement Validation Logic on Custom Objects.
  4. Inspect the control’s validation state. Examine Validation.HasError and Validation.Errors on the bound element. If HasError is true and Errors contains an entry, the binding has recorded a validation error; focus on how the UI displays it. A subsequent valid transfer can clear the error state.
  5. Inspect the control’s presentation. Look for a custom ErrorTemplate, styles that replace the default template, and a tooltip or other message element. A red border without explanatory text usually means the visual error cue is present but the message has no readable presentation.
  6. Check event notification and update timing if the error seems absent or late. The attached Validation.Error event is raised only for bindings with NotifyOnValidationError="True". Validation also depends on when the target value transfers to the source; check UpdateSourceTrigger if the rule appears to run only after a delay. WPF’s overview describes validation and source-update behavior: Data binding overview – WPF.

Show the error message in the control

A tooltip is one compact way to expose the first recorded error while retaining the normal validation border. The following illustrative pattern binds a TextBox to a property named Name, enables IDataErrorInfo validation, and shows the first error’s ErrorContent when the control has an error:

<TextBox>
  <TextBox.Style>
    <Style TargetType="TextBox">
      <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
          <Setter Property="ToolTip"
                  Value="{Binding RelativeSource={RelativeSource Self},
                                  Path=(Validation.Errors)[0].ErrorContent}" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </TextBox.Style>
  <TextBox.Text>
    <Binding Path="Name"
             ValidatesOnDataErrors="True"
             UpdateSourceTrigger="PropertyChanged" />
  </TextBox.Text>
</TextBox>

This follows the pattern in Microsoft’s validation-property example; adapt the property, control, and presentation to your view. A tooltip is not the only option: a custom ErrorTemplate or a separate message element can make errors easier to discover, especially where users may not hover over the control.

Choose between IDataErrorInfo and INotifyDataErrorInfo

Choose based on how the source manages validation and how much flexibility the application needs. Both interfaces still rely on WPF binding validation and a deliberate UI treatment for the error message.

Decision point IDataErrorInfo INotifyDataErrorInfo
How WPF uses it Enable ValidatesOnDataErrors or use a DataErrorValidationRule. The property indexer supplies the bound property’s error; the binding engine does not use the interface’s Error property for ordinary bound-property validation. Microsoft API reference; interface guidance. WPF checks for and reports errors from a source implementing the interface when ValidatesOnNotifyDataErrors is enabled. Its documented default is true. Microsoft API reference.
Best fit A simpler synchronous property-validation pattern when returning an error for a property is enough. A notification-based validation model when the application needs the added flexibility. Microsoft’s interface guidance identifies future asynchronous validation as a limitation of IDataErrorInfo; confirm behavior for the target framework and libraries.
Does it display explanatory text by itself? No. The validation state still needs an appropriate control presentation. No. The validation state still needs an appropriate control presentation.
Compatibility check Microsoft’s API reference lists the binding option across .NET Framework and Windows Desktop versions; check the target runtime and controls for the application. The API reference lists .NET Framework 4.5 onward and Windows Desktop 3.0 onward; check the target runtime and controls for the application.

Microsoft’s IDataErrorInfo guidance recommends that new entity classes generally prefer INotifyDataErrorInfo for its added flexibility. Treat that as guidance, not a universal rule: assess the target framework, validation workflow, and existing code before changing interfaces.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When the cause is still unclear

The exact cause in a specific application cannot be determined without its binding XAML, source object, target framework, control template, and runtime state. Use the checks above to separate a source or binding problem from a presentation problem; once Validation.HasError and Validation.Errors show what WPF recorded, investigate the relevant layer rather than switching interfaces at random.

Quick Recap

SaleBestseller No. 3
SaleBestseller No. 4
Programming WPF
Programming WPF
Used Book in Good Condition
$34.84
Bestseller No. 5
WPF 4.5 Unleashed
WPF 4.5 Unleashed
Used Book in Good Condition
$78.94
Best Value
WPF 4.5 Unleashed
  • Used Book in Good Condition
Rank #4
Sale
Programming WPF
  • Used Book in Good Condition

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.