Exemplo n.º 1
0
        public bool GetValue <T>(IStyleKey key, out T value)
        {
            if (elementStyle.GetValue(key, out value))
            {
                return(true);
            }
            if (!elementStyle.IsExplicitlyInherited(key))
            {
                if (ResolvedStyles.GetValue(key, out value))
                {
                    return(true);
                }
                if (!ResolvedStyles.IsExplicitlyInherited(key) && !key.Inherit)
                {
                    value = default(T);
                    return(false);
                }
            }

            // inheritance is potentially expensive, as we may traverse multiple
            // layers to get to the bottom of the tree. Caching is mandatory.
            object cachedValue;

            if (TryGetValue(key, out cachedValue))
            {
                value = (T)cachedValue;
                return(true);
            }

            var parentStyle = Self.GetStyleParent()?.Style;

            if (parentStyle != null)
            {
                if (parentStyle.GetValue(key, out value))
                {
                    Store(key, value);
                    return(true);
                }
            }

            value = default(T);
            Store(key, value);
            return(false);
        }