Example #1
0
        public static T GetValue <T>(this IStyle style, IStyleKey <T> key, T defaultValue = default(T))
        {
            T val;

            if (style.GetValue(key, out val))
            {
                return(val);
            }
            return(defaultValue);
        }
Example #2
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);
        }