예제 #1
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var color           = (Color)value;
            var defaultColorKey = (string)parameter;

            WBrush defaultBrush = defaultColorKey != null ? (WBrush)Microsoft.UI.Xaml.Application.Current.Resources[defaultColorKey] : new WSolidColorBrush(Colors.Transparent);

            return(color == Color.Default ? defaultBrush : color.ToBrush());
        }
예제 #2
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var color           = (Microsoft.Maui.Graphics.Color)value;
            var defaultColorKey = (string)parameter;

            WBrush defaultBrush = defaultColorKey != null ? (WBrush)Microsoft.UI.Xaml.Application.Current.Resources[defaultColorKey] : new WSolidColorBrush(Colors.Transparent);

            return(color.IsDefault() ? defaultBrush : Maui.ColorExtensions.ToNative(color));
        }
예제 #3
0
        void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            WireUpFormsVsm();

            // The defaults from the control template won't be available
            // right away; we have to wait until after the template has been applied
            _defaultBrush = Control.Foreground;
            UpdateFont();
            UpdateTextColor();
        }
예제 #4
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var color           = (Graphics.Color)value;
            var defaultColorKey = (string)parameter;

            WBrush defaultBrush = defaultColorKey != null ?
                                  (WBrush)UI.Xaml.Application.Current.Resources[defaultColorKey] :
                                  new WSolidColorBrush(Colors.Transparent);

            return(color.IsDefault() ? defaultBrush : color.ToPlatform());
        }
예제 #5
0
        void UpdateSelectedTabColors()
        {
            // Retrieve all tab header textblocks
            var allTabHeaderTextBlocks = Control.GetDescendantsByName <WTextBlock>(TabBarHeaderTextBlockName).ToArray();

            if (allTabHeaderTextBlocks.Length != Control.Items.Count)
            {
                return;
            }

            // Loop through all pages in the Pivot control
            foreach (Page page in Control.Items)
            {
                // Fetch just the textblock for the current page
                var tabBarTextBlock = allTabHeaderTextBlocks[Control.Items.IndexOf(page)];

                // Apply selected or unselected style to the current textblock
                if (page == Element.CurrentPage)
                {
                    if (_defaultSelectedColor == null)
                    {
                        _defaultSelectedColor = tabBarTextBlock.Foreground;
                    }

                    if (Element.IsSet(TabbedPage.SelectedTabColorProperty) && Element.SelectedTabColor != null)
                    {
                        tabBarTextBlock.Foreground = Element.SelectedTabColor.ToPlatform();
                    }
                    else
                    {
                        tabBarTextBlock.Foreground = _defaultSelectedColor;
                    }
                }
                else
                {
                    if (_defaultUnselectedColor == null)
                    {
                        _defaultUnselectedColor = tabBarTextBlock.Foreground;
                    }

                    if (Element.IsSet(TabbedPage.SelectedTabColorProperty) && Element.UnselectedTabColor != null)
                    {
                        tabBarTextBlock.Foreground = Element.UnselectedTabColor.ToPlatform();
                    }
                    else
                    {
                        tabBarTextBlock.Foreground = _defaultUnselectedColor;
                    }
                }
            }
        }
예제 #6
0
        public static void UpdateBrush(Brush brush, ref WBrush defaultbrush, Func <WBrush> getter, Action <WBrush> setter)
        {
            if (Brush.IsNullOrEmpty(brush))
            {
                if (defaultbrush == null)
                {
                    return;
                }

                setter(defaultbrush);
                return;
            }

            if (defaultbrush == null)
            {
                defaultbrush = getter();
            }

            setter(brush.ToBrush());
        }
예제 #7
0
        /// <summary>
        /// Handles the logic for setting a Xamarin.Forms Color for a Brush
        /// while caching the original default brush
        /// </summary>
        /// <param name="color">The target Xamarin.Forms.Color</param>
        /// <param name="defaultbrush">The renderer's cache for the default brush</param>
        /// <param name="getter">Delegate for retrieving the Control's current Brush</param>
        /// <param name="setter">Delegate for setting the Control's Brush</param>
        public static void UpdateColor(Color color, ref WBrush defaultbrush, Func <WBrush> getter, Action <WBrush> setter)
        {
            if (color.IsDefault)
            {
                if (defaultbrush == null)
                {
                    return;
                }

                setter(defaultbrush);
                return;
            }

            if (defaultbrush == null)
            {
                defaultbrush = getter();
            }

            setter(color.ToBrush());
        }
예제 #8
0
        /// <summary>
        /// Handles the logic for setting a Microsoft.Maui.Controls.Compatibility Color for a Brush
        /// while caching the original default brush
        /// </summary>
        /// <param name="color">The target Microsoft.Maui.Controls.Compatibility.Color</param>
        /// <param name="defaultbrush">The renderer's cache for the default brush</param>
        /// <param name="getter">Delegate for retrieving the Control's current Brush</param>
        /// <param name="setter">Delegate for setting the Control's Brush</param>
        public static void UpdateColor(Color color, ref WBrush defaultbrush, Func <WBrush> getter, Action <WBrush> setter)
        {
            if (color.IsDefault())
            {
                if (defaultbrush == null)
                {
                    return;
                }

                setter(defaultbrush);
                return;
            }

            if (defaultbrush == null)
            {
                defaultbrush = getter();
            }

            setter(Maui.ColorExtensions.ToNative(color));
        }
예제 #9
0
        internal void RefreshFlyoutBackdrop()
        {
            var dismissLayer = ((WRectangle)GetTemplateChild("LightDismissLayer"));

            if (dismissLayer == null)
            {
                return;
            }

            if (_defaultBrush == null)
            {
                _defaultBrush = dismissLayer.Fill;
            }

            if (Brush.IsNullOrEmpty(_flyoutBackdrop))
            {
                dismissLayer.Fill = _defaultBrush;
            }
            else
            {
                dismissLayer.Fill = _flyoutPlatformBrush ?? _defaultBrush;
            }
        }
예제 #10
0
        void UpdateOnColor()
        {
            if (Control == null)
            {
                return;
            }

            var grid = Control.GetFirstDescendant <WGrid>();

            if (grid == null)
            {
                return;
            }

            var groups = WVisualStateManager.GetVisualStateGroups(grid);

            foreach (var group in groups)
            {
                if (group.Name != ToggleSwitchCommonStates)
                {
                    continue;
                }

                foreach (var state in group.States)
                {
                    if (state.Name != ToggleSwitchPointerOver)
                    {
                        continue;
                    }

                    foreach (var timeline in state.Storyboard.Children.OfType <ObjectAnimationUsingKeyFrames>())
                    {
                        var property = Storyboard.GetTargetProperty(timeline);
                        var target   = Storyboard.GetTargetName(timeline);

                        if (target == ToggleSwitchKnobBounds && property == ToggleSwitchFillMode)
                        {
                            var frame = timeline.KeyFrames.FirstOrDefault();

                            if (frame != null)
                            {
                                if (_originalOnHoverColor == null)
                                {
                                    if (frame.Value is WColor color)
                                    {
                                        _originalOnHoverColor = color;
                                    }

                                    if (frame.Value is SolidColorBrush solidColorBrush)
                                    {
                                        _originalOnHoverColor = solidColorBrush;
                                    }
                                }

                                if (!Element.OnColor.IsDefault())
                                {
                                    frame.Value = new WSolidColorBrush(Element.OnColor.ToWindowsColor())
                                    {
                                        Opacity = _originalOnHoverColor is WSolidColorBrush originalOnHoverBrush ? originalOnHoverBrush.Opacity : 1
                                    };
                                }
                                else
                                {
                                    frame.Value = _originalOnHoverColor;
                                }
                            }
                            break;
                        }
                    }
                }
            }

            var rect = Control.GetDescendantsByName <WRectangle>(ToggleSwitchKnobBounds).FirstOrDefault();

            if (rect != null)
            {
                if (_originalOnColorBrush == null)
                {
                    _originalOnColorBrush = rect.Fill;
                }

                if (!Element.OnColor.IsDefault())
                {
                    rect.Fill = new WSolidColorBrush(Element.OnColor.ToWindowsColor());
                }
                else
                {
                    rect.Fill = _originalOnColorBrush;
                }
            }
        }
예제 #11
0
        void UpdateThumbColor()
        {
            if (Control == null)
            {
                return;
            }

            var grid = Control.GetFirstDescendant <WGrid>();

            if (grid == null)
            {
                return;
            }

            var groups = WVisualStateManager.GetVisualStateGroups(grid);

            foreach (var group in groups)
            {
                if (group.Name != ToggleSwitchCommonStates)
                {
                    continue;
                }

                foreach (var state in group.States)
                {
                    if (state.Name != ToggleSwitchPointerOver)
                    {
                        continue;
                    }

                    foreach (var timeline in state.Storyboard.Children.OfType <ObjectAnimationUsingKeyFrames>())
                    {
                        var property = Storyboard.GetTargetProperty(timeline);
                        var target   = Storyboard.GetTargetName(timeline);

                        if ((target == ToggleSwitchKnobOn) && (property == ToggleSwitchFillMode))
                        {
                            var frame = timeline.KeyFrames.FirstOrDefault();

                            if (frame != null)
                            {
                                if (_originalThumbOnBrush == null)
                                {
                                    if (frame.Value is Windows.UI.Color color)
                                    {
                                        _originalOnColorBrush = new WSolidColorBrush(color);
                                    }

                                    if (frame.Value is WBrush brush)
                                    {
                                        _originalThumbOnBrush = brush;
                                    }
                                }

                                if (!Element.ThumbColor.IsDefault())
                                {
                                    var brush = Maui.ColorExtensions.ToNative(Element.ThumbColor);
                                    brush.Opacity = _originalThumbOnBrush.Opacity;
                                    frame.Value   = brush;
                                }
                                else
                                {
                                    frame.Value = _originalThumbOnBrush;
                                }
                            }
                            break;
                        }
                    }
                }
            }

            if (grid.FindName(ToggleSwitchKnobOn) is WEllipse thumb)
            {
                if (_originalThumbOnBrush == null)
                {
                    _originalThumbOnBrush = thumb.Fill;
                }

                if (!Element.ThumbColor.IsDefault())
                {
                    thumb.Fill = Maui.ColorExtensions.ToNative(Element.ThumbColor);
                }
                else
                {
                    thumb.Fill = _originalThumbOnBrush;
                }
            }
        }