Exemplo n.º 1
0
        /// <summary>
        /// Sets the current OS theme using the given HighContrastTheme parameter
        /// </summary>
        /// <param name="theme"></param>
        public static void SetCurrent(HighContrastTheme theme)
        {
            var themes = new List <Theme>(Theme.GetAccessibleThemes());

            var hcTheme = themes.Find((Theme t) =>
            {
                return(string.Equals(t.Name, theme.ToString(), StringComparison.InvariantCultureIgnoreCase));
            });

            if (hcTheme == null)
            {
                throw new NotSupportedException($"Theme {theme.ToString()} is not supported");
            }

            Theme.SetCurrent(hcTheme);
        }
Exemplo n.º 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string[]          strArray = parameter.ToString().Split(',');
            HighContrastTheme theme    = HighContrastHelper.GetTheme(value);

            if (theme != HighContrastTheme.None)
            {
                if (strArray[0] == "HighContrastBlackAndWhiteEffect")
                {
                    HighContrastBlackAndWhiteEffect blackAndWhiteEffect = new HighContrastBlackAndWhiteEffect();
                    blackAndWhiteEffect.Invert = theme == HighContrastTheme.White ? 1.0 : 0.0;
                    if (strArray.Length == 2)
                    {
                        blackAndWhiteEffect.Amount = double.Parse(strArray[1], (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    return((object)blackAndWhiteEffect);
                }
                if (strArray[0] == "HighContrastInvertColorsEffect")
                {
                    HighContrastInvertColorsEffect invertColorsEffect = new HighContrastInvertColorsEffect();
                    invertColorsEffect.Invert = theme == HighContrastTheme.White ? 1.0 : 0.0;
                    if (strArray.Length == 3)
                    {
                        invertColorsEffect.Brightness = double.Parse(strArray[1], (IFormatProvider)CultureInfo.InvariantCulture);
                        invertColorsEffect.Contrast   = double.Parse(strArray[2], (IFormatProvider)CultureInfo.InvariantCulture);
                    }
                    return((object)invertColorsEffect);
                }
                if (strArray[0] == "MonochromeEffect")
                {
                    return (object)new MonochromeEffect()
                           {
                               Invert = (theme == HighContrastTheme.White ? 1.0 : 0.0)
                           }
                }
                ;
            }
            return((object)null);
        }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="theme"></param>
 public ThemeSwitcher(HighContrastTheme theme) : this()
 {
     Theme.SetCurrent(theme);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the current OS theme using the given HighContrastTheme parameter.
 /// </summary>
 /// <param name="theme"></param>
 /// <returns></returns>
 public static ThemeSwitcher SetTheme(HighContrastTheme theme)
 {
     return(new ThemeSwitcher(theme));
 }
Exemplo n.º 5
0
 public HighContrastProvider()
 {
     this.Theme = HighContrastHelper.CurrentTheme;
 }