Example #1
0
        /// <summary>
        /// Sets the value of a direct property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        private void SetDirectValue(AvaloniaProperty property, object value)
        {
            var notification = value as BindingNotification;

            if (notification != null)
            {
                if (notification.ErrorType == BindingErrorType.Error)
                {
                    Logger.Error(
                        LogArea.Binding,
                        this,
                        "Error in binding to {Target}.{Property}: {Message}",
                        this,
                        property,
                        ExceptionUtilities.GetMessage(notification.Error));
                }

                if (notification.HasValue)
                {
                    value = notification.Value;
                }
            }

            if (notification == null || notification.HasValue)
            {
                var metadata   = (IDirectPropertyMetadata)property.GetMetadata(GetType());
                var accessor   = (IDirectPropertyAccessor)GetRegistered(property);
                var finalValue = value == AvaloniaProperty.UnsetValue ?
                                 metadata.UnsetValue : value;

                LogPropertySet(property, value, BindingPriority.LocalValue);

                accessor.SetValue(this, finalValue);
            }

            if (notification != null)
            {
                UpdateDataValidation(property, notification);
            }
        }