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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:41:59+00:00 2026-06-07T03:41:59+00:00

I am having a difficult finding out how to do a conditional required validation.

  • 0

I am having a difficult finding out how to do a conditional required validation.

Basically I have an dialog object that needs to be validated. It has a bool which determines a certain state of the dialog.

If that state is true then a property needs to be validated, if it is false then the property is not used and thus needs no validation. At the same time I would like to retain the standard validation behavior when a value is not valid, namely the red border around the control that the property is bound to.

Example code on what I got:

public class Dialog
{
    public bool UseValidation { get; set; }

    [Required]
    [StringLength(15)]
    public string NotNullString { get; set; }
}

The reason for this is that I want to validate the dialog when the OK button is pressed, thus using the Validator.TryValidateObject() method.

  • 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-06-07T03:42:01+00:00Added an answer on June 7, 2026 at 3:42 am

    If you are using DataBinding, you can create explicit getters and setters for your property, and throw an exception if the data is not valid in the setter. You can then set the ValidatesOnException property of the textbox binding to True.

    public string NotNullString { 
       get { return _NotNullString; }
       set { 
              if(UseValidation && (String.IsNullOrEmpty(value) || value.Length > 15)) {
                  throw new Exception("Value must be between 1 and 15 characters long.");
              }
              _NotNullString = value;
           }
    }
    

    Here is a good article: http://www.codeproject.com/Articles/86955/Silverlight-4-Data-Validation-Tip-of-the-Day-Part

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

Sidebar

Related Questions

I'm having a difficult time finding any resources that describe good UI patterns for
I'm having a difficult time finding definitive information on this. If I have a
I'm currently having difficulty finding a way of making my loops work. I have
I'm having a difficult time figuring out how to add a .jar/library to a
I'm having a difficult time locating an HTML parser that works with JRuby. I've
Having a bit of difficulty finding out the proper way to mix in code
I'm having a difficult time finding specific info for my case. I'd like to
I'm having a difficult time finding how to do true data binding for UITableViews.
So, I'm having a difficult time (no pun intended) finding if an NSDate is
I'm having a difficult time finding any decent documentation for packaging on OSX. My

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.