protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
if (e.Property.Name == nameof(Validator))
{
ShowError = Validator.ValidationResult.Status == ValidationStatus.Invalid;
Visibility = ShowError ? Visibility.Visible : Visibility.Hidden;
Text = Validator.ValidationResult.Message;
// This might look like an event handler leak, but we're making sure Validator can only be set once.
// If we ever want to allow it to be set more than once, we'll need to make sure to unsubscribe this event.
Validator.PropertyChanged += (s, pce) =>
{
if (pce.PropertyName == nameof(Validator.ValidationResult))
{
ShowError = Validator.ValidationResult.Status == ValidationStatus.Invalid;
Visibility = ShowError ? Visibility.Visible : Visibility.Hidden;
Text = Validator.ValidationResult.Message;
}
};
}
base.OnPropertyChanged(e);
}