Exemplo n.º 1
0
        /// <summary>
        /// The SwitchModeCommandExecute.
        /// </summary>
        /// <returns>The <see cref="Task"/>.</returns>
        public static Task SwitchModeCommandExecute()
        {
            AppTheme appTheme = ThemeSettings.Theme;

            if (appTheme.Equals(AppTheme.Light))
            {
                Application.Current.Resources = new DarkTheme();

                IPlatformThemeManager platformManager = DependencyService.Get <IPlatformThemeManager>();

                platformManager?.ChangeTheme(AppTheme.Dark);

                ThemeSettings.Theme = AppTheme.Dark;
            }
            else
            {
                Application.Current.Resources = new LightTheme();

                IPlatformThemeManager platformManager = DependencyService.Get <IPlatformThemeManager>();

                // platformManager.ChangeTheme("light");
                platformManager?.ChangeTheme(AppTheme.Light);

                ThemeSettings.Theme = AppTheme.Light;
            }

            // App.MasterDetailPage.IsPresented = false;
            return(Task.FromResult(true));
        }
Exemplo n.º 2
0
        /// <summary>
        /// The LoadStyles.
        /// </summary>
        /// <returns>The <see cref="Task"/>.</returns>
        private Task LoadStyles()
        {
            AppTheme appTheme;

            // If this settings is not set, this must be the first time the user runs this App. Default to the Theme of the device
            // On Android and iOS, this works, but on UWP it will get the Theme of the App running, which is set in
            // App.xaml, RequestedTheme="Light"
            if (!App.Current.Properties.ContainsKey("Theme"))
            {
                appTheme            = AppInfo.RequestedTheme;
                ThemeSettings.Theme = appTheme;
            }
            else
            {
                appTheme = ThemeSettings.Theme;
            }

            IPlatformThemeManager platformManager = DependencyService.Get <IPlatformThemeManager>();

            platformManager?.ChangeTheme(appTheme);

            if (appTheme.Equals(AppTheme.Light))
            {
                Current.Resources = new LightTheme();
            }
            else
            {
                Current.Resources = new DarkTheme();
            }

            const int smallWidthResolution  = 768;
            const int smallHeightResolution = 1280;

            if (MainDisplayInfo.Width <= smallWidthResolution && MainDisplayInfo.Height <= smallHeightResolution)
            {
                this.AppDictionary.MergedDictionaries.Add(new SmallDeviceSizes());
            }
            else
            {
                this.AppDictionary.MergedDictionaries.Add(new DefaultSizes());
            }

            return(Task.FromResult(true));
        }
Exemplo n.º 3
0
 public ThemeManager(IPlatformThemeManager platformThemeManager)
 {
     this.platformThemeManager = platformThemeManager;
 }