ValidationResult ValidationResult ValidationResult ValidationResult Class

Definition

Represents the result returned by the ValidationRule.Validate(Object, CultureInfo) method that indicates whether the checked value passed the ValidationRule.

public ref class ValidationResult
public class ValidationResult
type ValidationResult = class
Public Class ValidationResult
Inheritance
ValidationResultValidationResultValidationResultValidationResult

Examples

The following example shows the implementation of a validation rule that marks the input value as invalid if it contains non-numeric characters or outside the lower and upper bounds. If the value is invalid, the ErrorContent property and the IsValid property of the returned ValidationResult are set to the appropriate error message and false respectively.

For the complete example, see How to: Implement Binding Validation.

public class AgeRangeRule : ValidationRule
{
    private int _min;
    private int _max;

    public AgeRangeRule()
    {
    }

    public int Min
    {
        get { return _min; }
        set { _min = value; }
    }

    public int Max
    {
        get { return _max; }
        set { _max = value; }
    }

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        int age = 0;

        try
        {
            if (((string)value).Length > 0)
                age = Int32.Parse((String)value);
        }
        catch (Exception e)
        {
            return new ValidationResult(false, "Illegal characters or " + e.Message);
        }

        if ((age < Min) || (age > Max))
        {
            return new ValidationResult(false,
              "Please enter an age in the range: " + Min + " - " + Max + ".");
        }
        else
        {
            return ValidationResult.ValidResult;
        }
    }
}

Remarks

The WPF data binding model enables you to associate ValidationRules with your Binding or MultiBinding object. You can create custom rules by subclassing the ValidationRule class and implementing the Validate method. The Validate method returns a ValidationResult object to report whether the checked value is valid.

For a detailed discussion of the validation process, see "Data Validation" in Data Binding Overview.

Constructors

ValidationResult(Boolean, Object) ValidationResult(Boolean, Object) ValidationResult(Boolean, Object) ValidationResult(Boolean, Object)

Initializes a new instance of the ValidationResult class.

Properties

ErrorContent ErrorContent ErrorContent ErrorContent

Gets an object that provides additional information about the invalidity.

IsValid IsValid IsValid IsValid

Gets a value that indicates whether the value checked against the ValidationRule is valid.

ValidResult ValidResult ValidResult ValidResult

Gets a valid instance of ValidationResult.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Compares the specified instance and the current instance of ValidationResult for value equality.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Returns the hash code for this ValidationResult.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Operators

Equality(ValidationResult, ValidationResult) Equality(ValidationResult, ValidationResult) Equality(ValidationResult, ValidationResult) Equality(ValidationResult, ValidationResult)

Compares two ValidationResult objects for value equality.

Inequality(ValidationResult, ValidationResult) Inequality(ValidationResult, ValidationResult) Inequality(ValidationResult, ValidationResult) Inequality(ValidationResult, ValidationResult)

Compares two ValidationResult objects for value inequality.

Applies to

See Also