Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:41:32+00:00 2026-05-11T08:41:32+00:00

I have a textbox in a WPF application bound to a property on a

  • 0

I have a textbox in a WPF application bound to a property on a Linq to Entities class that implements IDataErrorInfo. The textbox binding has ValidatesOnExceptions=True and ValidatesOnDataErrors=True. When the textbox is bound to an integer property and the user enters text then the textbox outline displays as red as I haven’t set up a custom style.

In my Save method how do I know the object can’t be saved as it’s invalid? I’d prefer the user clicks the Save button and I can notify them of a problem rather than disabling the Save button.

Cheers,

Dave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:41:33+00:00Added an answer on May 11, 2026 at 8:41 am

    I haven’t found an easy way to do it. I found some code around the traps to recurse through all the controls on the form and determine if any of them have validation errors. I ended up turning it into an extension method:

    // Validate all dependency objects in a window internal static IList<ValidationError> GetErrors(this DependencyObject node) {     // Check if dependency object was passed     if (node != null)     {         // Check if dependency object is valid.         // NOTE: Validation.GetHasError works for controls that have validation rules attached          bool isValid = !Validation.GetHasError(node);         if (!isValid)         {             // If the dependency object is invalid, and it can receive the focus,             // set the focus             if (node is IInputElement) Keyboard.Focus((IInputElement)node);             return Validation.GetErrors(node);         }     }      // If this dependency object is valid, check all child dependency objects     foreach (object subnode in LogicalTreeHelper.GetChildren(node))     {         if (subnode is DependencyObject)         {             // If a child dependency object is invalid, return false immediately,             // otherwise keep checking             var errors = GetErrors((DependencyObject)subnode);             if (errors.Count > 0) return errors;         }     }      // All dependency objects are valid     return new ValidationError[0]; } 

    So then when the user clicks the Save button on a form, I do this:

    var errors = this.GetErrors(); if (errors.Count > 0) {     MessageBox.Show(errors[0].ErrorContent.ToString());     return; } 

    It’s a lot more work than it should be, but using the extension method simplifies it a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer NHibernate Validator does not require you to use NHibernate for… May 11, 2026 at 2:52 pm
  • added an answer I needed this as well, and with the help of… May 11, 2026 at 2:52 pm
  • added an answer Thread-safe in which way? I don't see any part you… May 11, 2026 at 2:52 pm

Related Questions

I'm new to WPF and data binding so hopefully I can explain the problem
I'm trying to figure out how to read from the standard input stream of
I'm in the process of learning WPF coming from WinForms development. I have a
From what I understand, the goal of the Command pattern is to help separate

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.