/// <summary>
        /// Memoizer with one parameter (kept as weak reference), used to perform a lazy-cached evaluation. (see http://en.wikipedia.org/wiki/Memoization)
        /// </summary>
        /// <typeparam name="TParam">The return type to memoize</typeparam>
        /// <param name="func">the function to evaluate</param>
        /// <returns>A memoized value</returns>
        public static Func <TParam, TResult> AsWeakLockedMemoized <TParam, TResult>(this Func <TParam, TResult> func)
            where TParam : class
        {
            var values = new WeakAttachedDictionary <TParam, string>();

            return(v => values.GetValue(v, "value", () => func(v)));
        }
Пример #2
0
        private static bool GetNeedsKeyboard(UIView view)
        {
            var superViews = view.FindSuperviews().ToList();

            superViews.Insert(0, view);

            return(superViews.Any(superView => _attachedProperties.GetValue(superView, NeedsKeyboardAttachedPropertyKey, () => default(bool?)).GetValueOrDefault()));
        }
Пример #3
0
 public static TRenderer GetRenderer <TElement, TRenderer>(this TElement element, Func <TRenderer> rendererFactory)
     where TElement : DependencyObject
 {
     return(_renderers.GetValue(element, typeof(TRenderer), rendererFactory));
 }
Пример #4
0
 private static bool GetNeedsKeyboard(UIView view)
 {
     return(view != null && _attachedProperties.GetValue(view, NeedsKeyboardAttachedPropertyKey, () => default(bool?)).GetValueOrDefault());
 }
Пример #5
0
        internal static void SetForeground(this UIElement element, object localValue)
        {
            var brushSubscription = _imageBrushSubscription.GetValue(element, "foreground", () => new SerialDisposable());

            brushSubscription.Disposable = null;

            switch (localValue)
            {
            case SolidColorBrush scb:
                element.SetStyle("color", scb.ColorWithOpacity.ToHexString());
                break;

            case GradientBrush gradient:
                element.SetStyle(
                    ("background", gradient.ToCssString(element.RenderSize)),
                    ("color", "transparent"),
                    ("background-clip", "text")
                    );
                break;

            case ImageBrush imageBrush:
                brushSubscription.Disposable = imageBrush.Subscribe(img =>
                {
                    switch (img.Kind)
                    {
                    case ImageDataKind.Empty:
                    case ImageDataKind.Error:
                        element.ResetStyle(
                            "background-color",
                            "background-image",
                            "background-size");
                        element.SetStyle(
                            ("color", "transparent"),
                            ("background-clip", "text"));
                        break;

                    case ImageDataKind.DataUri:
                    case ImageDataKind.Url:
                    default:
                        element.SetStyle(
                            ("color", "transparent"),
                            ("background-clip", "text"),
                            ("background-color", ""),
                            ("background-origin", "content-box"),
                            ("background-position", imageBrush.ToCssPosition()),
                            ("background-size", imageBrush.ToCssBackgroundSize()),
                            ("background-image", "url(" + img.Value + ")")
                            );
                        break;
                    }
                });
                break;

            case AcrylicBrush acrylic:
                acrylic.Apply(element);
                element.SetStyle("background-clip", "text");
                break;

            case UnsetValue uv:

            // TODO: support other foreground types
            default:
                element.ResetStyle("color", "background", "background-clip");
                AcrylicBrush.ResetStyle(element);
                break;
            }
        }