Exemplo n.º 1
0
        private static void ApplyTheme(ThemeSetting theme)
        {
            var environment = DependencyService.Get <IEnvironment>();

            ResourceDictionary themeDict;
            SystemTheme        systemTheme = environment.GetOperatingSystemTheme();

            switch (theme)
            {
            case ThemeSetting.System:
                if (systemTheme == SystemTheme.Dark)
                {
                    themeDict = new DarkTheme();
                }
                else
                {
                    themeDict = new LightTheme();
                }
                break;

            case ThemeSetting.Light:
                themeDict   = new LightTheme();
                systemTheme = SystemTheme.Light;
                break;

            case ThemeSetting.Dark:
                themeDict   = new DarkTheme();
                systemTheme = SystemTheme.Dark;
                break;

            default:
                throw new NotImplementedException();
            }

            var styleDict = new ElementStyles();

            ICollection <ResourceDictionary> mergedDictionaries = currentApplication?.Resources.MergedDictionaries;

            if (mergedDictionaries != null)
            {
                mergedDictionaries.Clear();
                mergedDictionaries.Add(themeDict);

                // Need to merge theme into style dict before adding as style dict depends on theme
                styleDict.MergedDictionaries.Add(themeDict);
                mergedDictionaries.Add(styleDict);

                // Just add font dict since it doesn't depend on any others
                mergedDictionaries.Add(new AppFonts());
            }

            // Set system theme for platform-specific theming.
            environment.ApplyTheme(systemTheme);
        }
Exemplo n.º 2
0
 public void Init()
 {
     this.webElement = MockRepository.GenerateStub <IWebElement>();
     this.styles     = new ElementStyles(this.webElement);
 }