Пример #1
0
        static Color ObterCor(UIColorType casoEscuro, UIColorType casoClaro)
        {
            var tema = Application.Current.RequestedTheme;
            var cor  = tema == ApplicationTheme.Dark ? casoEscuro : casoClaro;

            return(new UISettings().GetColorValue(cor));
        }
        private Color Win10ColorToMediaColor(UISettings uiSettings, UIColorType colorType)
        {
            Windows.UI.Color win10Color = uiSettings.GetColorValue(colorType);
            Color            mediaColor = Color.FromArgb(win10Color.A, win10Color.R, win10Color.G, win10Color.B);

            return(mediaColor);
        }
Пример #3
0
        /// <summary>
        /// Returns the color value of the specified color type.
        /// </summary>
        /// <param name="desiredColor">An enumeration value that specifies the type of color to get a value for.</param>
        /// <returns>The color value of the specified color type.</returns>
        public Color GetColorValue(UIColorType desiredColor)
        {
#if WINDOWS_UWP
            return _settings.GetColorValue((Windows.UI.ViewManagement.UIColorType)((int)desiredColor));
#elif WIN32
            uint color = NativeMethods.GetSysColor(UIColorTypeToCOLOR(desiredColor));
            return Color.FromCOLORREF(color);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Пример #4
0
        private static int UIColorTypeToCOLOR(UIColorType t)
        {
            switch (t)
            {
            case UIColorType.Background:
                return(5);

            case UIColorType.Foreground:
                return(8);

            case UIColorType.Accent:
                return(13);
            }

            return(0);
        }
Пример #5
0
        private static int UIColorTypeToCOLOR(UIColorType t)
        {
            switch(t)
            {
                case UIColorType.Background:
                    return 5;

                case UIColorType.Foreground:
                    return 8;

                case UIColorType.Accent:
                    return 13;
            }

            return 0;
        }
Пример #6
0
        public Color GetColorValue(UIColorType desiredColor)
        {
            var systemTheme = SystemThemeHelper.SystemTheme;

            return(desiredColor switch
            {
                UIColorType.Background =>
                systemTheme == SystemTheme.Light ? Colors.White : Colors.Black,
                UIColorType.Foreground =>
                systemTheme == SystemTheme.Light ? Colors.Black : Colors.White,
                // The accent color values match SystemResources.xaml in Uno.UI
                // as we can't access Application resources from here directly.
                UIColorType.Accent => Color.FromArgb(255, 51, 153, 255),
                UIColorType.AccentDark1 => Color.FromArgb(255, 0, 90, 158),
                UIColorType.AccentDark2 => Color.FromArgb(255, 0, 66, 117),
                UIColorType.AccentDark3 => Color.FromArgb(255, 0, 38, 66),
                UIColorType.AccentLight1 => Color.FromArgb(255, 66, 156, 227),
                UIColorType.AccentLight2 => Color.FromArgb(255, 118, 185, 237),
                UIColorType.AccentLight3 => Color.FromArgb(255, 166, 216, 255),
                _ => Colors.Transparent
            });
Пример #7
0
        private static Color GetUIColor(UIColorType colorType)
        {
            var value = (_uiSettings ?? new UISettings()).GetColorValue(colorType);

            return(Color.FromArgb(value.A, value.R, value.G, value.B));
        }
Пример #8
0
        /// <summary>
        /// Returns the color value of the specified color type.
        /// </summary>
        /// <param name="desiredColor">An enumeration value that specifies the type of color to get a value for.</param>
        /// <returns>The color value of the specified color type.</returns>
        /// <remarks>
        /// <para/><list type="table">
        /// <listheader><term>Platform</term><description>Version supported</description></listheader>
        /// <item><term>tvOS</term><description>tvOS 9.0 and later</description></item>
        /// <item><term>Windows UWP</term><description>Windows 10 Mobile</description></item>
        /// <item><term>Windows Store</term><description>Windows 8.1 or later</description></item>
        /// <item><term>Windows Phone Store</term><description>Windows Phone 8.1 or later</description></item>
        /// <item><term>Windows Phone Silverlight</term><description>Windows Phone 8.0 or later</description></item>
        /// <item><term>Windows (Desktop Apps)</term><description>Windows 7 or later</description></item></list></remarks>
        public Color GetColorValue(UIColorType desiredColor)
        {
#if WINDOWS_UWP
            return(_settings.GetColorValue((Windows.UI.ViewManagement.UIColorType)((int)desiredColor)));
#elif WINDOWS_APP
            string key = null;
            switch (desiredColor)
            {
            case UIColorType.Foreground:
                key = "ApplicationForegroundThemeBrush";
                break;

            case UIColorType.Background:
                key = "ApplicationPageBackgroundThemeBrush";
                break;

            case UIColorType.Accent:
                key = "ListBoxItemSelectedBackgroundThemeBrush";
                break;
            }

            if (key != null)
            {
                Windows.UI.Color c = ((Windows.UI.Xaml.Media.SolidColorBrush)Windows.UI.Xaml.Application.Current.Resources[key]).Color;
                return(c);
            }

            return(Color.FromArgb(0, 0, 0, 0));
#elif WINDOWS_PHONE_APP
            string key = null;
            switch (desiredColor)
            {
            case UIColorType.Foreground:
                key = "PhoneForegroundColor";
                break;

            case UIColorType.Background:
                key = "PhoneBackgroundColor";
                break;

            case UIColorType.Accent:
                key = "SystemColorControlAccentColor";
                break;
            }

            if (key != null)
            {
                Windows.UI.Color c = (Windows.UI.Color)Windows.UI.Xaml.Application.Current.Resources[key];
                return(c);
            }

            return(Color.FromArgb(0, 0, 0, 0));
#elif WINDOWS_PHONE
            string key = null;
            switch (desiredColor)
            {
            case UIColorType.Foreground:
                key = "PhoneForegroundColor";
                break;

            case UIColorType.Background:
                key = "PhoneBackgroundColor";
                break;

            case UIColorType.Accent:
                key = "PhoneAccentColor";
                break;
            }

            if (key != null)
            {
                global::System.Windows.Media.Color c = (global::System.Windows.Media.Color)global::System.Windows.Application.Current.Resources[key];
                return(c);
            }

            return(Color.FromArgb(0, 0, 0, 0));
#elif WIN32
            uint color = NativeMethods.GetSysColor(UIColorTypeToCOLOR(desiredColor));
            return(Color.FromCOLORREF(color));
#elif __TVOS__
            bool isDark = UIScreen.MainScreen.TraitCollection.UserInterfaceStyle == UIUserInterfaceStyle.Dark;
            switch (desiredColor)
            {
            case UIColorType.Foreground:
                return(isDark ? Color.FromArgb(0xff, 0xff, 0xff) : Color.FromArgb(0, 0, 0));

            case UIColorType.Background:
                return(isDark ? Color.FromArgb(0, 0, 0) : Color.FromArgb(0xff, 0xff, 0xff));

            case UIColorType.Accent:
                return(UIScreen.MainScreen.FocusedView?.TintColor);
            }

            return(Color.FromArgb(0, 0, 0, 0));
#else
            throw new PlatformNotSupportedException();
#endif
        }
Пример #9
0
        /// <summary>
        /// Returns the color value of the specific color type in the system.
        /// </summary>
        public static Color GetSystemColor(UIColorType colorType)
        {
            UISettings settings = new UISettings();

            return(settings.GetColorValue(colorType));
        }
Пример #10
0
 public UIColorTypeListItem(UIColorType colorType, Color color)
 {
     ColorType = colorType;
     Color     = color;
 }