private object Translate(object o) { var weak = o as WeakReference; if (weak != null) { return(weak.Target); } else { var broken = BindingNotification.ExtractError(o) as MarkupBindingChainException; if (broken != null) { // We've received notification of a broken expression due to a null value // somewhere in the chain. If this null value occurs at the first node then we // ignore it, as its likely that e.g. the DataContext has not yet been set up. if (broken.HasNodes) { broken.Commit(Description); } else { o = AvaloniaProperty.UnsetValue; } } return(o); } }
private void ValueChanged(object value) { var broken = BindingNotification.ExtractError(value) as MarkupBindingChainException; broken?.Commit(Description); _value = new WeakReference<object>(value); PublishNext(value); }
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification status) { if (property == TextProperty) { DataValidationErrors.SetError(this, status.Error); } }
protected virtual void NextValueChanged(object value) { var bindingBroken = BindingNotification.ExtractError(value) as MarkupBindingChainNullException; bindingBroken?.AddNode(Description); _observer.OnNext(value); }
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification status) { if (property == TextProperty) { var classes = (IPseudoClasses)Classes; DataValidationErrors = UnpackException(status.Error); classes.Set(":error", DataValidationErrors != null); } }
/// <summary> /// Called when a priority level encounters an error. /// </summary> /// <param name="level">The priority level of the changed entry.</param> /// <param name="error">The binding error.</param> public void LevelError(PriorityLevel level, BindingNotification error) { Logger.Log( LogEventLevel.Error, LogArea.Binding, Owner, "Error in binding to {Target}.{Property}: {Message}", Owner, Property, error.Error.Message); }
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification status) { base.UpdateDataValidation(property, status); if (property == CommandProperty) { if (status?.ErrorType == BindingErrorType.Error) { IsEnabled = false; } } }
public object Convert(IList <object> values, Type targetType, object parameter, CultureInfo culture) { if (BindingNotification.ExtractValue(values[0]) == AvaloniaProperty.UnsetValue) { return(AvaloniaProperty.UnsetValue); } var condition = (bool)BindingNotification.ExtractValue(values[0]); var trueResult = (object)values[1]; var falseResult = (object)values[2]; return(condition ? trueResult : falseResult); }
protected virtual void NextValueChanged(object?value) { if (_subscriber is null) { return; } var bindingBroken = BindingNotification.ExtractError(value) as MarkupBindingChainException; bindingBroken?.AddNode(Description ?? "{empty}"); _subscriber(value); }
private object Translate(object o) { if (o is WeakReference weak) { return(weak.Target); } else if (BindingNotification.ExtractError(o) is MarkupBindingChainException broken) { broken.Commit(Description); } return(o); }
private static BindingNotification Merge(object a, BindingNotification b) { var an = a as BindingNotification; if (an != null) { Merge(an, b); return(an); } else { return(b); } }
private void OnValidationError(BindingNotification notification) { if (notification.Error != null) { _editBinding.AlterValidationErrors(errors => { errors.Clear(); var unpackedErrors = ValidationUtil.UnpackException(notification.Error); if (unpackedErrors != null) { errors.AddRange(unpackedErrors); } }); } }
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification status) { base.UpdateDataValidation(property, status); if (property == CommandProperty) { if (status?.ErrorType == BindingErrorType.Error) { if (_commandCanExecute) { _commandCanExecute = false; UpdateIsEffectivelyEnabled(); } } } }
private BindingNotification ConvertValue(BindingNotification notification) { if (notification.HasValue) { var converted = ConvertValue(notification.Value); notification = Merge(notification, converted); } else if (_fallbackValue != AvaloniaProperty.UnsetValue) { var fallback = ConvertFallback(); notification = Merge(notification, fallback); } return(notification); }
private static BindingNotification Merge(BindingNotification a, object b) { var bn = b as BindingNotification; if (bn != null) { Merge(a, bn); } else { a.SetValue(b); } return(a); }
/// <summary> /// Logs a mesage if the notification represents a binding error. /// </summary> /// <param name="property">The property being bound.</param> /// <param name="notification">The binding notification.</param> private void LogIfError(AvaloniaProperty property, BindingNotification notification) { if (notification.ErrorType == BindingErrorType.Error) { if (notification.Error is AggregateException aggregate) { foreach (var inner in aggregate.InnerExceptions) { LogBindingError(property, inner); } } else { LogBindingError(property, notification.Error); } } }
private static BindingNotification Merge(BindingNotification a, BindingNotification b) { if (b.HasValue) { a.SetValue(b.Value); } else { a.ClearValue(); } if (b.Error != null) { a.AddError(b.Error, b.ErrorType); } return(a); }
private object Translate(object o) { var weak = o as WeakReference; if (weak != null) { return(weak.Target); } else { var broken = BindingNotification.ExtractError(o) as MarkupBindingChainException; if (broken != null) { broken.Commit(Description); } return(o); } }
public static void LogIfError( this BindingNotification notification, object source, AvaloniaProperty property) { if (notification.ErrorType == BindingErrorType.Error) { if (notification.Error is AggregateException aggregate) { foreach (var inner in aggregate.InnerExceptions) { LogError(source, property, inner); } } else { LogError(source, property, notification.Error); } } }
private static object Negate(object?value) { var notification = value as BindingNotification; var v = BindingNotification.ExtractValue(value); BindingNotification GenerateError(Exception e) { notification ??= new BindingNotification(AvaloniaProperty.UnsetValue); notification.AddError(e, BindingErrorType.Error); notification.ClearValue(); return(notification); } if (v != AvaloniaProperty.UnsetValue) { var s = v as string; if (s != null) { bool result; if (bool.TryParse(s, out result)) { return(!result); } else { return(GenerateError(new InvalidCastException($"Unable to convert '{s}' to bool."))); } } else { try { var boolean = Convert.ToBoolean(v, CultureInfo.InvariantCulture); if (notification is object) { notification.SetValue(!boolean); return(notification); } else { return(!boolean); } } catch (InvalidCastException) { // The error message here is "Unable to cast object of type 'System.Object' // to type 'System.IConvertible'" which is kinda useless so provide our own. return(GenerateError(new InvalidCastException($"Unable to convert '{v}' to bool."))); } catch (Exception e) { return(GenerateError(e)); } } } return(notification ?? AvaloniaProperty.UnsetValue); }
/// <summary> /// Invoked when an entry in <see cref="Bindings"/> encounters a recoverable error. /// </summary> /// <param name="entry">The entry that completed.</param> /// <param name="error">The error.</param> public void Error(PriorityBindingEntry entry, BindingNotification error) { Owner.LevelError(this, error); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyError"/> class. /// </summary> /// <param name="error">The error to report.</param> public PropertyError(BindingNotification error) { _error = error; }
/// <summary> /// Called to update the validation state for properties for which data validation is /// enabled. /// </summary> /// <param name="property">The property.</param> /// <param name="status">The new validation status.</param> protected virtual void UpdateDataValidation( AvaloniaProperty property, BindingNotification status) { }
internal void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification) { UpdateDataValidation(property, notification); }
public void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification) { _owner.BindingNotificationReceived(property, notification); }
/// <inheritdoc/> void IPriorityValueOwner.BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification) { UpdateDataValidation(property, notification); }
protected override void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification) { Notifications.Add(notification); }
/// <inheritdoc/> void IPriorityValueOwner.BindingNotificationReceived(PriorityValue sender, BindingNotification notification) { UpdateDataValidation(sender.Property, notification); }
/// <summary> /// Called when a priority level encounters an error. /// </summary> /// <param name="level">The priority level of the changed entry.</param> /// <param name="error">The binding error.</param> public void LevelError(PriorityLevel level, BindingNotification error) { error.LogIfError(Owner, Property); }
protected override void UpdateDataValidation(AvaloniaProperty property, BindingNotification notification) { Notifications.Add(notification); }