コード例 #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);
        }
コード例 #2
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);
        }