Validating data in wpf

Rated 3.87/5 based on 841 customer reviews

Let’s just do something simple and display the message in a Tool Tip. Resources section that applies to the Textboxes on this form.

The Style sets up a Trigger that sets the Tool Tip property to the validation message when the Validation. What about the rest of our controls like Check Boxes, Combo Boxes, etc.?

Error Template property and its Value to our very own Control Template.

Now when we run this again, we still get our Tool Tip when we hover over the control, but now we’re also overlaying the control with Text Block we defined in our Control Template.

Then set the Window’s Data Context to the customer Data Table: WPF’s Default Validation Error Template So if we were to run this as-is WPF would give us a default visual cue when our validation fails.

As you can probably tell from my last couple posts I’ve been working with WPF in different data scenarios.

Yesterday I was playing with data validation in WPF and . In this article I’ll walk through how to hook up validation in your data objects using the IData Error Info interface and then I’ll go through a couple Validation Error Templates you can use to display the validation error messages and cues to the user.

We can completely change the Error Template that is used by defining a new one here in the Application. Let’s take a simple example by setting up our Error Template to display a generic message over the control.

In the Style above the Trigger section (we’ll leave the Tool Tip mesage there) we set the Validation.

Leave a Reply