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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:26:42+00:00 2026-05-17T16:26:42+00:00

I have a form: <StackPanel x:Name=LayoutRoot> <sdk:ValidationSummary /> <sdk:Label Target={Binding ElementName=Greeting} /> <TextBox x:Name=Greeting

  • 0

I have a form:

<StackPanel x:Name="LayoutRoot">
    <sdk:ValidationSummary />

    <sdk:Label Target="{Binding ElementName=Greeting}" />
    <TextBox x:Name="Greeting" Text="{Binding Greeting, Mode=TwoWay,
        ValidatesOnExceptions=True, NotifyOnValidationError=True}" />

    <sdk:Label Target="{Binding ElementName=Name}" />
    <TextBox x:Name="Name" Text="{Binding Name, Mode=TwoWay,
        ValidatesOnExceptions=True, NotifyOnValidationError=True}" />
</StackPanel>

And a simple class this is set as the DataContext…

  public class Person : INotifyPropertyChanged
    {
        private string _greeting;

        private string _name;

        public string Greeting
        {
            get { return _greeting; }
            set
            {
                _greeting = value;
                InvokePropertyChanged(new PropertyChangedEventArgs("Greeting"));
            }
        }

        [Required(ErrorMessage = "Name must be provided")]
        [StringLength(15, MinimumLength = 5,
            ErrorMessage = "Name should be 5 to 15 characters")]
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                InvokePropertyChanged(new PropertyChangedEventArgs("Name"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void InvokePropertyChanged(PropertyChangedEventArgs e)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, e);
        }
    }

I set the data context with the following line in the code behind of the xaml:

    DataContext = new Person {Name = "Joe User"};

I see the data on the form, and the label for Name is bold, indicating required. However, if I empty the field, or set it to a string of an invalid length, I get no validation, on the label itself, or the validation summary. I understand the textbox doesn’t validate until lost focus, so I click into the greeting field and enter text to make sure I’ve left the other text control.

What am I missing here?

Answer:

Per @Alex Paven’s answer, to get it to work with Data Annotations you would use:

[Required(ErrorMessage = "Name must be provided")]
[StringLength(15, MinimumLength = 5,
    ErrorMessage = "Name should be 5 to 15 characters")]
public string Name
{
    get { return _name; }
    set
    {
        Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "Name" });
        _name = value;
        InvokePropertyChanged(new PropertyChangedEventArgs("DisplayName"));
    }
}

As for IDataErrorInfo, I’ll look into it. 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-17T16:26:43+00:00Added an answer on May 17, 2026 at 4:26 pm

    You’re missing the actual validation call. With ValidatesOnExceptions, an exception must be thrown in the property setter, and the attributes are not taken into account automatically with respect to validation. For it to work you need a call to System.ComponentModel.DataAnnotations.Validator.ValidateProperty with the correct parameters.

    However, if using Silverlight 4, I’d suggest looking into validating with IDataErrorInfo, as I feel it offers a lot more flexibility.

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

Sidebar

Related Questions

No related questions found

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.