ValidationResult.ErrorContent Свойство
Определение
Получает объект с дополнительными сведениями о недопустимости.Gets an object that provides additional information about the invalidity.
public:
property System::Object ^ ErrorContent { System::Object ^ get(); };
public object ErrorContent { get; }
member this.ErrorContent : obj
Public ReadOnly Property ErrorContent As Object
Значение свойства
Объект с дополнительными сведениями о недопустимости.An object that provides additional information about the invalidity.
Примеры
В следующем примере показана реализация правила проверки, которое помечает входное значение как недопустимое, если оно содержит нечисловые символы или находится за пределами нижней и верхней границ.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. Если значение недопустимо, то ErrorContent свойству и IsValid возвращаемому свойству ValidationResult присваивается соответствующее сообщение об ошибке и false
соответственно.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
{
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 позволяет связываться ValidationRules с Binding MultiBinding объектом или.The WPF data binding model enables you to associate ValidationRules with your Binding or MultiBinding object. Пользовательские правила можно создавать путем создания подклассов ValidationRule класса и реализации Validate метода.You can create custom rules by subclassing the ValidationRule class and implementing the Validate method. ValidateМетод возвращает объект, ValidationResult сообщающий, является ли проверяемое значение допустимым.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.