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

The Archive Base Latest Questions

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

I have a user control which contains a textbox. I have a class called

  • 0

I have a user control which contains a textbox. I have a class called Person which implements IDataErrorInfo interface:

class Person : IDataErrorInfo { private bool hasErrors = false; #region IDataErrorInfo Members          public string Error         {                         get              {                 string error = null;                 if (hasErrors)                 {                     error = 'xxThe form contains one or more validation errors';                 }                 return error;             }         }          public string this[string columnName]         {             get              {                 return DoValidation(columnName);             }         }         #endregion } 

Now the usercontrol exposes a method called SetSource through which the code sets the binding:

public partial class TxtUserControl : UserControl      {                   private Binding _binding;          public void SetSource(string path,Object source)         {             _binding = new Binding(path);             _binding.Source = source;             ValidationRule rule;             rule = new DataErrorValidationRule();             rule.ValidatesOnTargetUpdated = true;                         _binding.ValidationRules.Add(rule);             _binding.ValidatesOnDataErrors = true;             _binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;             _binding.NotifyOnValidationError = true;                         _binding.ValidatesOnExceptions = true;             txtNumeric.SetBinding(TextBox.TextProperty, _binding);                         } ... } 

The WPF window that includes the user control has the following code:

public SampleWindow()     {         person= new Person();         person.Age = new Age();         person.Age.Value = 28;          numericAdmins.SetSource('Age.Value', person);     }     private void btnOk_Click(object sender, RoutedEventArgs e)     {                   if(!String.IsNullOrEmpty(person.Error))         {             MessageBox.Show('Error: '+person.Error);         }     } 

Given this code, the binding is working fine, but the validation never gets triggered. Whats wrong with this code?

  • 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:26:44+00:00Added an answer on May 11, 2026 at 8:26 am

    Your Age class will need to implement IDataErrorInfo. Your Person class won’t be asked to validate the Age‘s properties.

    If that is not an option, I wrote a validation system for WPF that is extensible enough to support this. The URL is here:

    • http://paulstovell.com/Downloads/ValidationScopes.zip

    In the ZIP is a word document describing it.

    Edit: here’s one way age could implement IDataErrorInfo without being too smart:

    class Constraint  {     public string Message { get; set; }     public Func<bool> Validate;     public string Name { get; set; } }  class Age : IDataErrorInfo {     private readonly List<Constraint> _constraints = new List<Constraint>();      public string this[string columnName]     {         get          {             var constraint = _constrains.Where(c => c.Name == columnName).FirstOrDefault();             if (constraint != null)             {                 if (!constraint.Validate())                 {                     return constraint.Message;                 }             }             return string.Empty;         }     } }  class Person {     private Age _age;      public Person()      {         _age = new Age(             new Constraint('Value', 'Value must be greater than 28', () => Age > 28);     } } 

    Also see this link:

    http://www.codeproject.com/KB/cs/DelegateBusinessObjects.aspx

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • 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
  • Editorial Team
    Editorial Team added an answer Judging from what you've presented, you've got a couple of… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer Our company uses PL/SQL Developer. I am not familiar with… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer I have no idea why you'd want to do this,… May 11, 2026 at 4:39 pm

Related Questions

I have a user control that contains a 2-column TableLayoutPanel and accepts commands to
I have UserControl which contains a TextBox and a Button control. The Button opens
I have an ASP.Net web user control that contains a TextBox and a calendar
I have a Flex application where I'm using a Canvas to contain several other

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.