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 6876165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:38+00:00 2026-05-27T04:26:38+00:00

Here is what I have: In the view there is a tab control with

  • 0

Here is what I have:

In the view there is a tab control with two tabs (sys1 and sys2) each with the same textboxes that are bound to the properties of their respective entities:

sys1:

<TextBox Text="{Binding sys1.Serial, ValidatesOnExceptions=True, NotifyOnValidationError=True}" />

sys2:

<TextBox Text="{Binding sys2.Serial, ValidatesOnExceptions=True, NotifyOnValidationError=True}" />

Using some form of validation I would like to compare the two values and display an error (red border is fine) if the values don’t match.

I’ve used IDataErrorInfo before, but I’m not sure if this type of validation is possible.

Note: whether or not binding directly to the entity is “correct” is a discussion for another place and time. Just know that this is a team project and our teams standards are to bind to the entity so I can’t change that unless I have a good reason. Perhaps if it’s not possible validating when bound directly to the entity then I may have a good enough reason to change this.

Thanks

  • 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-27T04:26:38+00:00Added an answer on May 27, 2026 at 4:26 am

    I usually expose a Validation Delegate from my Model that my ViewModel can use to attach business-rule validation to the Models.

    For example, the ViewModel containing your objects might look like this:

    public ParentViewModel()
    {
        sys1.AddValidationErrorDelegate(ValidateSerial);
        sys2.AddValidationErrorDelegate(ValidateSerial);
    }
    
    private string ValidateSerial(object sender, string propertyName)
    {
        if (propertyName == "Serial")
        {
            if (sys1.Serial == sys2.Serial)
                return "Serial already assigned";
        }
        return null;
    }
    

    The idea is that your Model should only contain raw data, therefore it should only validate raw data. This can include validating things like maximum lengths, required fields, and allowed characters. Business Logic, which includes business rules, should be validated in the ViewModel and this allows that to happen.

    The actual implementation of my IDataErrorInfo on the Model class would look like this:

    #region IDataErrorInfo & Validation Members
    
    /// <summary>
    /// List of Property Names that should be validated
    /// </summary>
    protected List<string> ValidatedProperties = new List<string>();
    
    #region Validation Delegate
    
    public delegate string ValidationErrorDelegate(object sender, string propertyName);
    
    private List<ValidationErrorDelegate> _validationDelegates = new List<ValidationErrorDelegate>();
    
    public void AddValidationErrorDelegate(ValidationErrorDelegate func)
    {
        _validationDelegates.Add(func);
    }
    
    #endregion // Validation Delegate
    
    #region IDataErrorInfo for binding errors
    
    string IDataErrorInfo.Error { get { return null; } }
    
    string IDataErrorInfo.this[string propertyName]
    {
        get { return this.GetValidationError(propertyName); }
    }
    
    public string GetValidationError(string propertyName)
    {
        // If user specified properties to validate, check to see if this one exists in the list
        if (ValidatedProperties.IndexOf(propertyName) < 0)
        {
            //Debug.Fail("Unexpected property being validated on " + this.GetType().ToString() + ": " + propertyName);
            return null;
        }
    
        string s = null;
    
        // If user specified a Validation method to use, Validate property
        if (_validationDelegates.Count > 0)
        {
            foreach (ValidationErrorDelegate func in _validationDelegates)
            {
                s = func(this, propertyName);
                if (s != null)
                {
                    return s;
                }
            }
        }
    
        return s;
    }
    
    #endregion // IDataErrorInfo for binding errors
    
    #region IsValid Property
    
    public bool IsValid
    {
        get
        {
            return (GetValidationError() == null);
        }
    }
    
    public string GetValidationError()
    {
        string error = null;
    
        if (ValidatedProperties != null)
        {
            foreach (string s in ValidatedProperties)
            {
                error = GetValidationError(s);
                if (error != null)
                {
                    return error;
                }
            }
        }
    
        return error;
    }
    
    #endregion // IsValid Property
    
    #endregion // IDataErrorInfo & Validation Members
    

    P.S. I see nothing wrong with binding directly to the Model, especially in smaller applications. It may not be the “MVVM-purist” approach, however it is efficient and a lot less work, so I find it a perfectly valid option.

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

Sidebar

Related Questions

Here's the setup: I have a tab bar controller with two tabs. There is
I have an application with a tab bar controller and each view contains a
I'm having a problem with the WPF Tab View control that I was hoping
I have a user control that is binded to a view model and I
I have a tab bar app that works. Each tab is a UINavigationController whose
In my Silverlight app I have a view containing a tab control and a
Here is my scenario. I have 3 out of 4 tab views that contain
Ok Here is the exact scenario: I have a view named Index I have
Here's my case: I have a table view showing contacts. Add button in the
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->

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.