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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:49:10+00:00 2026-05-22T00:49:10+00:00

I am creating an MVVM Silverlight application and am trying to add validation to

  • 0

I am creating an MVVM Silverlight application and am trying to add validation to my Model.

In this particular instance I have multiple phone number boxes and have the requirement that at least one phone number must be entered. To facilitate I have my properties (HomePhone, WorkPhone, MobilePhone and OtherPhone) on my model decorated with an a CustomValidation attribute.

Example property:

    private string _otherPhone;
    [CustomValidation(typeof(MyModel), "ValidatePhoneNumbers")]
    public string OtherPhone
    {
        get { return _otherPhone; }
        set
        {
            if (_otherPhone == value) return;
            _otherPhone = value;
            Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "OtherPhone" });
            RaisePropertyChanged(() => HomePhone);
            RaisePropertyChanged(() => WorkPhone);
            RaisePropertyChanged(() => MobilePhone);
            RaisePropertyChanged(() => OtherPhone);
        }
    }

Along with the custom validator itself:

    public static ValidationResult ValidatePhoneNumbers(string number, ValidationContext validationContext)
    {
        MyModel myModel = (MyModel)validationContext.ObjectInstance;
        return string.IsNullOrEmpty(myModel.HomePhone) && string.IsNullOrEmpty(myModel.WorkPhone) && string.IsNullOrEmpty(myModel.MobilePhone) && string.IsNullOrEmpty(myModel.OtherPhone)
                   ? new ValidationResult("At least one phone number must be entered")
                   : ValidationResult.Success;
    }

I have ensured that the backing store is set in the property setter before the validation is run, to ensure that the ValidatePhoneNumbers method is able to check the latest value.

When I try to save my model, I am executing UpdateBindingExpression on all the bindings in the View. Now this works correctly the first time that I try to save, and all four fields are highlighted as having an error.

If I try to save again however, all fields are marked as passed validation, and a breakpoint in ValidatePhoneNumbers is never hit. Why is 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-22T00:49:11+00:00Added an answer on May 22, 2026 at 12:49 am

    I’m sure that every time that I spend long enough fighting a bug to resort to posting on SO, I work out what the actual answer is 20 seconds later… The if (_otherPhone == value) return; was causing the validation not to run – this optimisation would make sense if the validation wasn’t dependent on another property.

    Never mind…

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

Sidebar

Related Questions

When creating a test project for a Silverlight MVVM application, should I create a
I am creating a Silverlight 4 application with Entity Framework, RIA Services and MVVM-Light
I'm creating a Silverlight 3.0 MVVM application using Silverlight.FX but my View is actually
When creating a web application, and lets say you have a User object denoting
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I am creating a WPF/MVVM framework which generates the code for the model classes.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
While creating classes in Java I often find myself creating instance-level collections that I
I am creating a UserControl in Silverlight 4 which has a watermarked background. The
Creating an Iphone application, I used to perform INSERT QUERY on different databases. But

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.