Пример #1
0
        // create dependency property entry and set its default and initial inherited value
        private IDependencyPropertyValueEntry CreateDependencyPropertyValueEntry(DependencyProperty dependencyProperty, PropertyMetadata propertyMetadata)
        {
            bool isContained = dependencyProperty.IsAttached || dependencyProperty.IsContainedBy(GetType());

            IDependencyPropertyValueEntry entry = new DependencyPropertyValueEntry(this, dependencyProperty, isContained ? propertyMetadata.CoerceValueCallback : null);

            entry.SetBaseValue((int)BaseValueSource.Default, propertyMetadata.DefaultValue);

            if (isContained)
            {
                entry.ValueChanged += containedEntryValueChangedEventHandler;
            }
            else
            {
                entry.ValueChanged += entryValueChangedEventHandler;
            }

            return(entry);
        }
Пример #2
0
        public object GetValue(DependencyProperty dependencyProperty)
        {
            IDependencyPropertyValueEntry entry;

            if (!entries.TryGetValue(dependencyProperty, out entry))
            {
                PropertyMetadata propertyMetadata = dependencyProperty.GetMetadata(GetType());

                // no need to create a new entry if the value is not inherited or coerced
                if (!propertyMetadata.Inherits && (propertyMetadata.CoerceValueCallback == null || !dependencyProperty.IsAttached && !dependencyProperty.IsContainedBy(GetType())))
                {
                    return(propertyMetadata.DefaultValue);
                }

                entry = CreateDependencyPropertyValueEntry(dependencyProperty, propertyMetadata);
                entries.Add(dependencyProperty, entry);
            }

            return(entry.Value);
        }