how to pass property values between xaml files?

时间:2015-07-28 15:35:22

标签: wpf validation xaml

i have made a usercontrol and used that in several XAML files. i want to apply a validation on that usercontrol for a specific XAML file where i used that. what i was doing is making a property in usercontrol called "MaxValue" and other property in specific XAML file i.e. "Maximum" now i want to set Maximum to 255 in Specific XAML file and want to bind that Maximum to MaxValue... i was doing it but it was not reflecting.... i want to validate the usercontrol on the basis of the value which was provided in the xaml file where it used

public class ColorValueValidator : ValidationRule {

private MaxChecker validRange;

public MaxChecker ValidRange
{
    get { return validRange; }
    set { validRange = value; }
}

public override ValidationResult Validate
 (object value, System.Globalization.CultureInfo cultureInfo)
{
    int colorValue;

    int maxCheck = ValidRange.Maximum;

    if (value != null)
    {
        if (Int32.TryParse(value.ToString(), out colorValue))
        {
            if ((colorValue < 0) || (colorValue > 255))
            {
                return new ValidationResult(false, "Value should be between 0 to 255.");
            }
            else
            {
                return new ValidationResult(true, null);
            }

        }
        else
        {
            return new ValidationResult(false, "Please enter a correct Value.");
        }

    }
    else
    {
        return new ValidationResult(false, "Please enter a correct Value.");
    }
}

}

public class MaxChecker : DependencyObject {

public int Maximum
{
    get { return (int)GetValue(MaximumProperty); }
    set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
    DependencyProperty.Register("Maximum", typeof(int), typeof(MaxChecker), new UIPropertyMetadata(int.MaxValue));

}' this is the validator function . i want to use this with my user control but i want to specify the maximun value in the corresponding xaml file where the user control is used

0 个答案:

没有答案