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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:44+00:00 2026-05-23T09:47:44+00:00

I have ValidationRule Class for Discount Percentage Validation (as below) public class DiscountPerRule :

  • 0

I have ValidationRule Class for Discount Percentage Validation (as below)

public class DiscountPerRule : ValidationRule
{
    public float Min { get; set; }

    public float Max { get; set; }

    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        float _prm = 0f;
        try
        {
            if (value.ToString().Length > 0)
            {
                _prm = float.Parse(value.ToString());
            }
        }
        catch
        {
            return new ValidationResult(false, "Illegal Characters, Please Enter Numaric Value");
        }
        if ((_prm < Min) || (_prm > Max))
        {
            return new ValidationResult(false, String.Format("Please enter value in the Range: {0} - {1}.", this.Min, this.Max));
        }
        return new ValidationResult(true, null);
    }
}

In XAML we use this ValiationRule class as below and set Min and Max Properties in ValidationRules Tag

<TextBox x:Name="txtDisPer" Width="108" HorizontalAlignment="Center" VerticalAlignment="Center" Validation.Error="txtDisPer_Error" >
    <Binding Path="Rate" UpdateSourceTrigger="PropertyChanged" ValidatesOnExceptions="True" ValidatesOnDataErrors="True" NotifyOnValidationError="True" Mode="TwoWay" NotifyOnSourceUpdated="True" NotifyOnTargetUpdated="True">
        <Binding.ValidationRules>
            <local:DiscountPerRule Max="100" Min="0"/>
        </Binding.ValidationRules>
    </Binding>
</TextBox>

So, How to assign/Reassign Min and Max value at runtime(Programaticaly) in C# 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. Editorial Team
    Editorial Team
    2026-05-23T09:47:45+00:00Added an answer on May 23, 2026 at 9:47 am

    The easiest way would be to name the validation rule in your XAML:

    <local:DiscountPerRule x:Name="discountPerRule" Max="100" Min="0"/>
    

    And then use code like this in your code-behind to alter it:

    discountPerRule.Min = 10;
    discountPerRule.Max = 50;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ValidationRule class in WPF public class EmptyFieldValidationRule: BaseValidationRule { public
I'm trying to perform a validation property. We have a nullable property called: public
I have a model with validation rule like this public function rules() { return
I have added a css class validation rule for jquery validator as follows: jQuery.validator.addClassRules({
Does anyone have a simple example of implementing an async validation rule in csla?
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have the following validation code processed for my User Model. It works good
I've only scraped the surface of validation in WPF and have come across a
I have a user control which contains a textbox. I have a class called
I have a property on my view model that is a custom class with

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.