ValidationResult.ErrorContent プロパティ

定義

無効性に関する追加情報を提供するオブジェクトを取得します。

public:
 property System::Object ^ ErrorContent { System::Object ^ get(); };
public object ErrorContent { get; }
member this.ErrorContent : obj
Public ReadOnly Property ErrorContent As Object

プロパティ値

Object

無効性に関する追加情報を提供するオブジェクト。

次の例は、入力値に数値以外の文字が含まれている場合、または下限と上限の外側にある場合に無効としてマークする検証規則の実装を示しています。 値が無効な場合、ErrorContent返されるValidationResultプロパティとIsValidプロパティはそれぞれ適切なエラー メッセージfalseに設定されます。

完全な例については、「 方法: バインド検証を実装する」を参照してください。

public class AgeRangeRule : ValidationRule
{
    public int Min { get; set; }
    public int Max { get; set; }
    
    public AgeRangeRule()
    {
    }

    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}.");
        }
        return ValidationResult.ValidResult;
    }
}

注釈

WPF データ バインディング モデルを使用すると、自分BindingまたはMultiBindingオブジェクトに関連付けることができますValidationRules。 クラスをサブクラス化し、メソッドを ValidationRule 実装することで、カスタム ルールを Validate 作成できます。 このメソッドは Validate 、チェックされた ValidationResult 値が有効かどうかを報告するオブジェクトを返します。

検証プロセスの詳細については、「データ バインディングの概要」の「データ検証」を参照してください。

適用対象