Beispiel #1
0
        private T GetValueOrInheritedOrDefault <T>(StyledPropertyBase <T> property)
        {
            var o        = this;
            var inherits = property.Inherits;
            var value    = default(T);

            while (o != null)
            {
                var values = o._values;

                if (values?.TryGetValue(property, out value) == true)
                {
                    return(value);
                }

                if (!inherits)
                {
                    break;
                }

                o = o.InheritanceParent as AvaloniaObject;
            }

            return(property.GetDefaultValue(GetType()));
        }
Beispiel #2
0
        private T GetInheritedOrDefault <T>(StyledPropertyBase <T> property)
        {
            if (property.Inherits && InheritanceParent is AvaloniaObject o)
            {
                return(o.GetValueOrInheritedOrDefault(property));
            }

            return(property.GetDefaultValue(GetType()));
        }
Beispiel #3
0
        /// <summary>
        /// Called for each inherited property when the <see cref="InheritanceParent"/> changes.
        /// </summary>
        /// <typeparam name="T">The type of the property value.</typeparam>
        /// <param name="property">The property.</param>
        /// <param name="oldParent">The old inheritance parent.</param>
        internal void InheritanceParentChanged <T>(
            StyledPropertyBase <T> property,
            IAvaloniaObject oldParent)
        {
            var oldValue = oldParent switch
            {
                AvaloniaObject o => o.GetValueOrInheritedOrDefault(property),
                null => property.GetDefaultValue(GetType()),
                _ => oldParent.GetValue(property)
            };

            var newValue = GetInheritedOrDefault(property);

            if (!EqualityComparer <T> .Default.Equals(oldValue, newValue))
            {
                RaisePropertyChanged(property, oldValue, newValue);
            }
        }