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

  • Home
  • SEARCH
  • 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 995247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:41:37+00:00 2026-05-16T06:41:37+00:00

I’m looking for a way to validate all the data on a form that

  • 0

I’m looking for a way to validate all the data on a form that has tabs and the tabs contain data templates. I’ve been looking all over and found a similar question here: http://www.netframeworkdev.com/windows-presentation-foundation-wpf/wpf-validation-data-templates-74176.shtml, but that didn’t get a good answer.

Walking the logical tree to check all controls seems to stop at the data template.
Walking the visual tree does not include controls that are not on the currently visible tab.
Using IDataError does not catch invalid input such as letters in a textbox that is bound to a number.

Is there a simple, clean solution to this?

Any help would be much appreciated.

  • 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. Editorial Team
    Editorial Team
    2026-05-16T06:41:37+00:00Added an answer on May 16, 2026 at 6:41 am

    I think the root of your problem is that your view model isn’t really a model of the view.

    Every property in the view model should be of a type appropriate for the view, not the data model. If you have a numeric property in the data model and you’re using a text box in the view to edit it, the property in the view model should be a string.

    The view model properties contain the values appearing in the view irrespective of whether or not those values are valid. The only time there should be a discrepancy between the value in the view and the value in the view model is when an editable control has the focus, the user is changing its value, and binding hasn’t pushed the new value back to the view model yet.

    If you do it this way, I think most of the concerns you’ve expressed here go away. After you populate a view model object (assuming that you’ve implemented validation in its setters, and you’re not bypassing its setters to update the properties’ backing fields directly), its properties are valid or not irrespective of whether or not its view has been instantiated yet.

    In my view model classes, I implement a Dictionary<string, string> property named Errors. The validation in the property setters populates Errors with each property’s validation error, or null if the property is valid. This makes implementing IDataErrorInfo.Item simple:

    public string this[string propertyName]
    {
       get
       {
          return Errors.ContainsKey(propertyName) ? Errors[propertyName] : null;
       }
    }
    

    I can also implement this property:

    public bool IsValid { get { return !(Errors.Values(x => x != null).Any()); } }
    

    which can be used anywhere I need to check to make sure that the view model’s current state is valid – say, in the CanExecute property of a Command.

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

Sidebar

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.