|
|
@ -22,8 +22,8 @@ namespace Avalonia.Controls |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the DataValidationErrors.Errors attached property.
|
|
|
/// Defines the DataValidationErrors.Errors attached property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static readonly AttachedProperty<IEnumerable<Exception>> ErrorsProperty = |
|
|
public static readonly AttachedProperty<IEnumerable<object>> ErrorsProperty = |
|
|
AvaloniaProperty.RegisterAttached<DataValidationErrors, Control, IEnumerable<Exception>>("Errors"); |
|
|
AvaloniaProperty.RegisterAttached<DataValidationErrors, Control, IEnumerable<object>>("Errors"); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the DataValidationErrors.HasErrors attached property.
|
|
|
/// Defines the DataValidationErrors.HasErrors attached property.
|
|
|
@ -76,7 +76,7 @@ namespace Avalonia.Controls |
|
|
private static void ErrorsChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
private static void ErrorsChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
{ |
|
|
{ |
|
|
var control = (Control)e.Sender; |
|
|
var control = (Control)e.Sender; |
|
|
var errors = (IEnumerable<Exception>)e.NewValue; |
|
|
var errors = (IEnumerable<object>)e.NewValue; |
|
|
|
|
|
|
|
|
var hasErrors = false; |
|
|
var hasErrors = false; |
|
|
if (errors != null && errors.Any()) |
|
|
if (errors != null && errors.Any()) |
|
|
@ -91,11 +91,11 @@ namespace Avalonia.Controls |
|
|
classes.Set(":error", (bool)e.NewValue); |
|
|
classes.Set(":error", (bool)e.NewValue); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static IEnumerable<Exception> GetErrors(Control control) |
|
|
public static IEnumerable<object> GetErrors(Control control) |
|
|
{ |
|
|
{ |
|
|
return control.GetValue(ErrorsProperty); |
|
|
return control.GetValue(ErrorsProperty); |
|
|
} |
|
|
} |
|
|
public static void SetErrors(Control control, IEnumerable<Exception> errors) |
|
|
public static void SetErrors(Control control, IEnumerable<object> errors) |
|
|
{ |
|
|
{ |
|
|
control.SetValue(ErrorsProperty, errors); |
|
|
control.SetValue(ErrorsProperty, errors); |
|
|
} |
|
|
} |
|
|
@ -112,14 +112,14 @@ namespace Avalonia.Controls |
|
|
return control.GetValue(HasErrorsProperty); |
|
|
return control.GetValue(HasErrorsProperty); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static IEnumerable<Exception> UnpackException(Exception exception) |
|
|
private static IEnumerable<object> UnpackException(Exception exception) |
|
|
{ |
|
|
{ |
|
|
if (exception != null) |
|
|
if (exception != null) |
|
|
{ |
|
|
{ |
|
|
var aggregate = exception as AggregateException; |
|
|
var aggregate = exception as AggregateException; |
|
|
var exceptions = aggregate == null ? |
|
|
var exceptions = aggregate == null ? |
|
|
(IEnumerable<Exception>)new[] { exception } : |
|
|
new[] { GetExceptionData(exception) } : |
|
|
aggregate.InnerExceptions; |
|
|
aggregate.InnerExceptions.Select(GetExceptionData).ToArray(); |
|
|
var filtered = exceptions.Where(x => !(x is BindingChainException)).ToList(); |
|
|
var filtered = exceptions.Where(x => !(x is BindingChainException)).ToList(); |
|
|
|
|
|
|
|
|
if (filtered.Count > 0) |
|
|
if (filtered.Count > 0) |
|
|
@ -130,5 +130,13 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static object GetExceptionData(Exception exception) |
|
|
|
|
|
{ |
|
|
|
|
|
if (exception is DataValidationException dataValidationException) |
|
|
|
|
|
return dataValidationException.ErrorData; |
|
|
|
|
|
|
|
|
|
|
|
return exception; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|