Esempio n. 1
0
        public object GetValue(AttachedProperty property, object instance)
        {
            AttachedPropertyMetadata metadata;

            if (!metadataStore.TryGetMetadata(property.OwnerType, property, out metadata))
            {
                throw new InvalidOperationException();
            }

            if (metadata.Inherits)
            {
                object val;
                if (TryGetValueFromParentTree(property, instance, out val))
                {
                    return(val);
                }
            }
            else
            {
                object val;
                var    prop = new AttachedPropertyEntry(property, instance);
                if (values.TryGetValue(prop, out val))
                {
                    return(val);
                }
            }

            return(metadata.DefaultValue);
        }
Esempio n. 2
0
        public AttachedProperty RegisterProperty(string name, Type ownerType, Type propertyType,
                                                 AttachedPropertyMetadata propertyMetadata)
        {
            var prop = new AttachedProperty(ownerType, propertyType, name);

            metadataStore.RegisterMetadata(ownerType, prop, propertyMetadata);
            return(prop);
        }
Esempio n. 3
0
        private bool TryGetValueFromParentTree(AttachedProperty property, object instance, out object val)
        {
            do
            {
                var prop = new AttachedPropertyEntry(property, instance);
                if (values.TryGetValue(prop, out val))
                {
                    return(true);
                }

                instance = getParentFunc(instance);
            } while (instance != null);

            return(false);
        }
Esempio n. 4
0
 public void SetValue(AttachedProperty property, object instance, object value)
 {
     values.Add(new AttachedPropertyEntry(property, instance), value);
 }
Esempio n. 5
0
 protected bool Equals(AttachedProperty other)
 {
     return(OwnerType == other.OwnerType && PropertyType == other.PropertyType && string.Equals(Name, other.Name));
 }