Esempio n. 1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var mode = "L";

            if (parameter != null)
            {
                mode = "D";

                if ((string)parameter == "W")
                {
                    mode = "W";
                }
            }

            Color color;

            if (value.GetType() == typeof(SolidColorBrush))
            {
                color = ((SolidColorBrush)value).Color;
            }
            else if (value.ToString().StartsWith("#"))
            {
                color = ColorUtility.CreateBrush(value.ToString()).Color;
            }

            if (mode == "L")
            {
                color = ColorUtility.Lighten(color);
            }
            else if (mode == "W")
            {
                color = ColorUtility.Desaturate(color, 0.1f);
            }
            else
            {
                color = ColorUtility.Darken(color);
            }

            if (targetType == typeof(Color))
            {
                return(color);
            }

            return(ColorUtility.CreateBrush(color));
        }
Esempio n. 2
0
        private static void OnAccentChanged(Color obj)
        {
            //Calculate the new accent dark and light:
            var accentLight    = ColorUtility.CreateBrush(ColorUtility.Lighten(Accent));
            var accentDark     = ColorUtility.CreateBrush(ColorUtility.Darken(Accent));
            var accentDisabled = ColorUtility.CreateBrush(ColorUtility.Desaturate(Accent, 0.1f));
            var accentShifted  = ColorUtility.HueShift(Accent, 20);

            var bright = ColorUtility.CreateBrush("#ffffff");
            var dark   = ColorUtility.CreateBrush("#1A1A1A");

            _dictionary["Accent"]         = ColorUtility.CreateBrush(Accent);
            _dictionary["AccentLight"]    = accentLight;
            _dictionary["AccentDark"]     = accentDark;
            _dictionary["AccentDisabled"] = accentDisabled;
            _dictionary["AccentGradient"] = ColorUtility.CreateBrush(Accent, accentShifted);

            if (Theme == ThemeMode.Dark)
            {
                _dictionary["AccentDarkDynamic"]   = accentDark;
                _dictionary["AccentLightDynamic"]  = accentLight;
                _dictionary["PanelGray"]           = ColorUtility.CreateBrush("#4D4D4D");
                _dictionary["PanelBackground"]     = dark;
                _dictionary["PanelForeground"]     = bright;
                _dictionary["PanelGrayResponsive"] = ColorUtility.CreateBrush("#303030");
            }
            else
            {
                _dictionary["AccentDarkDynamic"]   = accentLight;
                _dictionary["AccentLightDynamic"]  = accentDark;
                _dictionary["PanelGray"]           = ColorUtility.CreateBrush("#999999");
                _dictionary["PanelBackground"]     = bright;
                _dictionary["PanelForeground"]     = dark;
                _dictionary["PanelGrayResponsive"] = ColorUtility.CreateBrush("#F2F2F2");
            }
        }