Пример #1
0
        public static double GetOpacity(this View view, ControlState state = ControlState.Default)
        {
            var opacity = view?.GetEnvironment <double?>(EnvironmentKeys.View.Opacity, state);

            //Fall back to the default state before using the default color
            opacity ??= view?.GetEnvironment <double?>(EnvironmentKeys.View.Opacity);
            return(opacity ?? 1);
        }
Пример #2
0
        public static FontAttributes GetFont(this View view, FontAttributes defaultFont)
        {
            var size   = view.GetEnvironment <float?>(EnvironmentKeys.Fonts.Size) ?? defaultFont.Size;
            var name   = view.GetEnvironment <string>(EnvironmentKeys.Fonts.Family) ?? defaultFont.Family;
            var weight = view.GetEnvironment <Weight?>(EnvironmentKeys.Fonts.Weight) ?? defaultFont.Weight;
            var italic = view.GetEnvironment <bool?>(EnvironmentKeys.Fonts.Italic) ?? defaultFont.Italic;

            return(new FontAttributes
            {
                Size = size,
                Family = name,
                Italic = italic,
                Weight = weight,
            });
        }
Пример #3
0
        public static LayoutAlignment GetVerticalLayoutAlignment(this View view, ContainerView container, LayoutAlignment defaultSizing = LayoutAlignment.Start)
        {
            var sizing = view.GetEnvironment <LayoutAlignment?>(view, EnvironmentKeys.Layout.VerticalLayoutAlignment);

            if (sizing != null)
            {
                return((LayoutAlignment)sizing);
            }

            if (container != null)
            {
                sizing = view.GetEnvironment <LayoutAlignment?>(view, $"{container.GetType().Name}.{EnvironmentKeys.Layout.VerticalLayoutAlignment}");
            }
            return(sizing ?? defaultSizing);
        }
Пример #4
0
        public static Sizing GetVerticalSizing(this View view, ContainerView container, Sizing defaultSizing = Sizing.Fit)
        {
            var sizing = view.GetEnvironment <Sizing?>(view, EnvironmentKeys.Layout.VerticalSizing);

            if (sizing != null)
            {
                return((Sizing)sizing);
            }

            if (container != null)
            {
                sizing = view.GetEnvironment <Sizing?>(view, $"{container.GetType().Name}.{EnvironmentKeys.Layout.VerticalSizing}");
            }
            return(sizing ?? defaultSizing);
        }
Пример #5
0
        public static string GetTitle(this View view)
        {
            var title = view?.GetEnvironment <string>(EnvironmentKeys.View.Title);

            title ??= view?.BuiltView?.GetEnvironment <string>(EnvironmentKeys.View.Title, true) ?? "";
            return(title);
        }
Пример #6
0
        public static Font GetFont(this View view, Font?defaultFont)
        {
            Font font   = Font.Default;
            var  size   = view.GetEnvironment <double?>(EnvironmentKeys.Fonts.Size) ?? defaultFont?.Size ?? font.Size;
            var  name   = view.GetEnvironment <string>(EnvironmentKeys.Fonts.Family) ?? defaultFont?.Family ?? font.Family;
            var  weight = view.GetEnvironment <FontWeight?>(EnvironmentKeys.Fonts.Weight) ?? defaultFont?.Weight ?? Microsoft.Maui.FontWeight.Regular;
            var  slant  = view.GetEnvironment <FontSlant?>(EnvironmentKeys.Fonts.Slant) ?? Microsoft.Maui.FontSlant.Default;

            if (!string.IsNullOrWhiteSpace(name))
            {
                return(Font.OfSize(name, size, weight, slant));
            }
            //else if (size > 0)
            return(Font.SystemFontOfSize(size, weight, slant));
            //return font;
        }
Пример #7
0
        public static Paint GetBackground(this View view, Paint defaultColor = null, ControlState state = ControlState.Default)
        {
            var color = view?.GetEnvironment <object>(EnvironmentKeys.Colors.Background, state);

            return(color.ConvertToPaint() ?? defaultColor);
        }
Пример #8
0
 public static View GetOverlay(this View view)
 {
     return(view.GetEnvironment <View>(EnvironmentKeys.View.Overlay));
 }
Пример #9
0
        public static TextAlignment?GetVerticalTextAlignment(this View view, TextAlignment?defaultValue = null)
        {
            var value = view.GetEnvironment <TextAlignment?>(view, EnvironmentKeys.Text.VerticalAlignment);

            return(value ?? defaultValue);
        }
Пример #10
0
        public static Color GetBackgroundColor(this View view, Color defaultColor = null, ControlState state = ControlState.Default)
        {
            var color = view?.GetEnvironment <Color>(EnvironmentKeys.Colors.BackgroundColor, state);

            return(color ?? defaultColor);
        }
Пример #11
0
        public static Shape GetClipShape(this View view, Shape defaultShape = null, Type type = null)
        {
            var shape = view.GetEnvironment <Shape>(type, EnvironmentKeys.View.ClipShape);

            return(shape ?? defaultShape);
        }
Пример #12
0
 public static Shape GetOverlay(this View view)
 {
     return(view.GetEnvironment <Shape>(EnvironmentKeys.View.Overlay));
 }
Пример #13
0
 public static bool GetIgnoreSafeArea(this View view, bool defaultValue) => (bool?)view.GetEnvironment(view, EnvironmentKeys.Layout.IgnoreSafeArea, false) ?? defaultValue;
Пример #14
0
        public static Thickness GetPadding(this View view, Thickness?defaultValue = null)
        {
            var margin = view.GetEnvironment <Thickness?>(view, EnvironmentKeys.Layout.Padding);

            return(margin ?? defaultValue ?? Thickness.Zero);
        }
Пример #15
0
        public static Thickness GetMargin(this View view, Thickness?defaultValue = null)
        {
            var margin = view.GetEnvironment <Thickness?>(view, EnvironmentKeys.Layout.Margin);

            return(margin ?? defaultValue ?? Thickness.Empty);
        }
Пример #16
0
        public static Sizing GetVerticalSizing(this View view, Sizing defaultSizing = Sizing.Fit)
        {
            var sizing = view.GetEnvironment <Sizing?>(view, EnvironmentKeys.Layout.VerticalSizing);

            return(sizing ?? defaultSizing);
        }
Пример #17
0
        public static Shadow GetShadow(this View view, Shadow defaultShadow = null, Type type = null)
        {
            var shadow = view.GetEnvironment <Shadow>(type, EnvironmentKeys.View.Shadow);

            return(shadow ?? defaultShadow);
        }
Пример #18
0
        public static FrameConstraints GetFrameConstraints(this View view, FrameConstraints defaultContraints = null)
        {
            var constraints = view.GetEnvironment <FrameConstraints>(view, EnvironmentKeys.Layout.FrameConstraints);

            return(constraints ?? defaultContraints);
        }
Пример #19
0
        public static Color GetNavigationTextColor(this View view, Color defaultColor = null)
        {
            var color = view.GetEnvironment <Color>(EnvironmentKeys.Navigation.TextColor);

            return(color ?? defaultColor);
        }
Пример #20
0
        public static Thickness GetPadding(this View view, Thickness?defaultValue = null)
        {
            var padding = view.GetEnvironment <Thickness?>(view, EnvironmentKeys.Layout.Padding);

            return(padding ?? defaultValue ?? Thickness.Empty);
        }
Пример #21
0
        public static Animation GetAnimation(this View view)
        {
            var animation = view.GetEnvironment <Animation>(EnvironmentKeys.Animations.Animation);

            return(animation);
        }
Пример #22
0
        public static object GetLayoutConstraints(this View view, object defaultValue = null)
        {
            var constraints = view.GetEnvironment <object>(view, EnvironmentKeys.Layout.Constraints);

            return(constraints ?? defaultValue);
        }
Пример #23
0
        public static Color GetBackgroundColor(this View view, Color defaultColor = null)
        {
            var color = view.GetEnvironment <Color>(EnvironmentKeys.Colors.BackgroundColor);

            return(color ?? defaultColor);
        }
Пример #24
0
 public static string GetAutomationId(this View view)
 => view.GetEnvironment <string>(view, EnvironmentKeys.View.AutomationId, cascades: false);