/// <summary> /// Sets the theme for the app. /// </summary> async Task SetAppTheme(AppThemeViewModel theme) { try { Application.Current.UserAppTheme = theme.Key; Settings.AppTheme = theme.Key; foreach (var item in AppThemes) { item.IsSelected = false; } AppThemes.FirstOrDefault(x => x.Key == Settings.AppTheme).IsSelected = true; RaisePropertyChanged(nameof(AppThemes)); //var statusBar = DependencyService.Get<IStatusBar>(); //statusBar?.SetStatusBarColor((OSAppTheme)theme.Key, Color.Black); HapticFeedback.Perform(HapticFeedbackType.Click); AnalyticsService.Track("App Theme Changed", nameof(theme), ((OSAppTheme)theme.Key).ToString() ?? "null"); } catch (Exception ex) { await DialogService.AlertAsync(Translations.error_couldntchangetheme, Translations.error_title, Translations.ok).ConfigureAwait(false); AnalyticsService.Report(ex); } }
private static void SaveThemeInSettings(AppThemes theme) { if (!SettingsService.Instance.UseSystemAppTheme) { SettingsService.Instance.AppTheme = (ApplicationTheme)theme; } }
void SetAppTheme(AppThemeViewModel theme) { foreach (var item in AppThemes) { item.IsSelected = false; } switch (theme.Key) { case 0: Application.Current.UserAppTheme = OSAppTheme.Unspecified; Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Unspecified); break; case 1: Application.Current.UserAppTheme = OSAppTheme.Light; Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Light); break; case 2: Application.Current.UserAppTheme = OSAppTheme.Dark; Preferences.Set(Settings.AppTheme, (int)OSAppTheme.Dark); break; default: break; } AppThemes.FirstOrDefault(x => x.Key == Preferences.Get(Settings.AppTheme, Settings.AppThemeDefault)).IsSelected = true; RaisePropertyChanged(nameof(AppThemes)); }
public SettingsWindowViewModel() : base() { AccentColors = ThemeManager.Current.Themes .GroupBy(x => x.ColorScheme) .OrderBy(a => a.Key) .Select(a => new AccentColorMenuData { Name = a.Key, ColorBrush = a.First().ShowcaseBrush }) .ToList(); AccentColor = AccentColors.First(x => x.Name == App.Theme.ColorScheme); AppThemes = ThemeManager.Current.Themes .GroupBy(x => x.BaseColorScheme) .Select(x => x.First()) .Select(a => new AppThemeMenuData { Name = a.BaseColorScheme, BorderColorBrush = a.Resources["MahApps.Brushes.ThemeForeground"] as Brush, ColorBrush = a.Resources["MahApps.Brushes.ThemeBackground"] as Brush }) .ToList(); AppTheme = AppThemes.First(x => x.Name == App.Theme.BaseColorScheme); var resources = App.Theme.LibraryThemes.First(x => x.Origin == "MahApps.Metro").Resources.MergedDictionaries.First(); Colors = typeof(Colors).GetProperties(BindingFlags.Public | BindingFlags.Static) .Where(x => x.Name != "Transparent") .Select(x => new AccentColorMenuData { Name = x.Name, ColorBrush = new SolidColorBrush((Color)x.GetValue(null)) }) .ToList(); }
public void Apply(ApplicationDesign design) { try { design.AccentColor.ApplyTheme(); } catch (Exception) { design.AccentColor = AccentColors.First(x => x.Name == "Blue"); design.AccentColor.ApplyTheme(); } try { design.AppTheme.ApplyTheme(); } catch (Exception) { design.AppTheme = AppThemes.First(); design.AppTheme.ApplyTheme(); } if (design.AudioVisualisation != null) { design.AudioVisualisation.AudioVisualisationPlugin.Refresh(); } }
/// <summary> /// Initializes a new instance of the <see cref="SettingsViewModel"/> class. /// </summary> /// <param name="logger">Logger dependency.</param> /// <param name="localization">Localization provider dependency.</param> /// <param name="options">Surrent settings.</param> /// <param name="settingsService">Settings service dependency.</param> public SettingsViewModel(ILogger logger, ILocalization localization, AppSettings options, SettingsService settingsService) { CultureSelectionChangedCommand = new DelegateCommand(ChangeCulture); this.logger = logger; this.localization = localization; this.options = options; this.settingsService = settingsService; AppThemes = ThemeManager.Current.Themes .GroupBy(x => x.BaseColorScheme) .Select(x => x.First()) .ToList(); ColorThemes = ThemeManager.Current.ColorSchemes.OrderBy(x => x).ToList(); Theme?currentTheme = ThemeManager.Current.DetectTheme(); if (currentTheme != null) { SelectedAppTheme = AppThemes.First(x => x.BaseColorScheme == currentTheme.BaseColorScheme); SelectedColor = ColorThemes.First(x => x == currentTheme.ColorScheme); } ShowLastWeekSuggestion = options.ShowLastWeekSuggestion; }
public ThemePickerViewModel(IAnalyticsService analyticsService, IAuthService authService, IDialogService dialogService, INavigationHelper navigationHelper) : base(analyticsService, authService, dialogService, navigationHelper) { SetAppThemeCommand = new Command <AppThemeViewModel>((x) => SetAppTheme(x)); AppThemes.FirstOrDefault(x => x.Key == Preferences.Get(Settings.AppTheme, Settings.AppThemeDefault)).IsSelected = true; }
/// <summary> /// Update the selected item property for each theme/accent when the theme/accent is changed /// </summary> private void ThemeManager_IsThemeChanged(object sender, OnThemeChangedEventArgs e) { OnPropertyChanged("CurrentAppTheme"); OnPropertyChanged("CurrentAppAccent"); AppThemes.ForEach(t => t.IsSelectedItem = (t == CurrentAppTheme)); AccentColors.ForEach(a => a.IsSelectedItem = (a == CurrentAppAccent)); }
public static void SetTheme(AppThemes theme) { Theme = theme; SetRequestedTheme(); SaveThemeInSettings(Theme); OnThemeChanged(null, Theme); }
private void LoadDefaults() { if (!this.IsInDesignMode) { SelectedAppTheme = AppThemes.FirstOrDefault(at => at.Name == App.SelectedAppTheme.Name); SelectedAccent = AccentColors.FirstOrDefault(ac => ac.Name == App.SelectedAccent.Name); SelectedLang = App.Language; App.LanguageChanged += AppOnLanguageChanged; } }
/// <summary> /// Load the saved theme and accent /// </summary> public void LoadSavedTheme() { // Get the saved theme and accent AppThemeMenuData savedTheme = AppThemes.Where(t => t.Name == Properties.Settings.Default.AppTheme).FirstOrDefault(); AccentColorMenuData savedAccent = AccentColors.Where(a => a.Name == Properties.Settings.Default.AppAccent).FirstOrDefault(); // Change to the saved theme and accent savedTheme?.ChangeAccentCommand.Execute(null); savedAccent?.ChangeAccentCommand.Execute(null); }
public static void SetDefaultResources(AppThemes appThemes) { var styleSource = StyleSelector(appThemes); foreach (var item in styleSource) { var source = item; Extensions.SetResource(source); } }
public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme) { if (resources == null) { throw new ArgumentNullException("resources"); } AppTheme appTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]); ChangeAppStyle(resources, newAccent, appTheme); }
public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme) { if (window == null) { throw new ArgumentNullException("window"); } var oldTheme = DetectTheme(window); AppTheme oldAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[oldTheme.Item1]); AppTheme newAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]); ChangeAppStyle(window.Resources, Tuple.Create(oldAppTheme, oldTheme.Item2), newAccent, newAppTheme); }
private void WindowThemeUserControl_Loaded(object sender, RoutedEventArgs e) { Window window = Window.GetWindow(this); window.Closing += window_Closing; // Get the saved theme and accent AppThemeMenuData savedTheme = AppThemes.Where(t => t.Name == Properties.Settings.Default.AppTheme).FirstOrDefault(); AccentColorMenuData savedAccent = AccentColors.Where(a => a.Name == Properties.Settings.Default.AppAccent).FirstOrDefault(); // Change to the saved theme and accent savedTheme?.ChangeAccentCommand.Execute(null); savedAccent?.ChangeAccentCommand.Execute(null); }
private static AppThemes LoadThemeFromSettings() { AppThemes cacheTheme = AppThemes.System; if (!SettingsService.Instance.UseSystemAppTheme) { cacheTheme = (AppThemes)SettingsService.Instance.AppTheme; } else { cacheTheme = (AppThemes)SettingsService.Instance.SystemTheme; } return(cacheTheme); }
private static IEnumerable<string> StyleSelector(AppThemes appThemes) { IEnumerable<string> styleSource; switch (appThemes) { case AppThemes.Red: styleSource = RedTheme.GetFilePaths(); break; case AppThemes.Blue: default: styleSource = BlueThemes.GetFilePaths(); break; } return styleSource; }
/// <summary> /// Selects The Theme To Display. /// </summary> /// <param name="ThemeName">The Theme Name.</param> public void SelectTheme(string ThemeName) { //Make Sure It Exists if (!AppThemes.ContainsKey(ThemeName)) { throw new KeyNotFoundException($"The Specified Theme Name, {ThemeName} Could Not Be Located."); } //Set Theme CurrentThemeName = ThemeName; //Check If Event Exists if (AppThemeChange != null) { //Update Event AppThemeChange.Invoke(this, new ThemeChangeArgs(ThemeName, CurrentTheme)); } }
public void LoadData() { ThemeAccents = ThemeManager.Accents .Select(a => new Utils.Theme { ColorName = a.Name, BrushTheme = a.Resources["AccentColorBrush"] as Brush }) .ToList(); AppThemes = ThemeManager.AppThemes .Select(a => new Utils.Theme { ColorName = a.Name, BrushBorder = a.Resources["BlackColorBrush"] as Brush, BrushTheme = a.Resources["WhiteColorBrush"] as Brush }) .ToList(); SelectedThemeColor = ThemeAccents.SingleOrDefault(c => c.ColorName == Settings.Default.ThemeColor); SelectedThemeStyle = AppThemes.SingleOrDefault(c => c.ColorName == Settings.Default.ThemeStyle); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ThemeAccents))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(AppThemes))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedThemeColor))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedThemeStyle))); }
public static void SelectTheme(AppThemes theme = AppThemes.Light) { if (theme == AppThemes.FollowSystem) { theme = IsSystemUsingDarkTheme() ? AppThemes.Dark : AppThemes.Light; } //Checks if the theme is already the current in use. var last = Application.Current.Resources.MergedDictionaries.LastOrDefault(l => l.Source != null && l.Source.ToString().Contains("Colors/")); if (last?.Source.ToString().EndsWith($"/{theme}.xaml") == true) { return; } //Tries to switch to the new theme. var res = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith($"Colors/{theme}.xaml")); if (res == null) { res = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith("Colors/Light.xaml")); UserSettings.All.MainTheme = AppThemes.Light; } Application.Current.Resources.MergedDictionaries.Remove(res); Application.Current.Resources.MergedDictionaries.Add(res); //Forces the refresh of the vectors with dynamic resources inside. var glyphs = Application.Current.Resources.MergedDictionaries.FirstOrDefault(f => f.Source != null && f.Source.ToString().EndsWith("Resources/Glyphs.xaml")); Application.Current.Resources.MergedDictionaries.Remove(glyphs); Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new System.Uri("Resources/Glyphs.xaml", System.UriKind.RelativeOrAbsolute) }); RefreshNotificationIcon(); }
private void SetTheme(AppThemes theme) { Uri uri; switch (theme) { case AppThemes.Aero: uri = new Uri("PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/Aero.NormalColor.xaml", UriKind.Relative); break; case AppThemes.Luna: uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.NormalColor.xaml", UriKind.Relative); break; case AppThemes.LunaHomestead: uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.Homestead.xaml", UriKind.Relative); break; case AppThemes.LunaMetallic: uri = new Uri("PresentationFramework.Luna;V3.0.0.0;31bf3856ad364e35;component\\themes/Luna.Metallic.xaml", UriKind.Relative); break; case AppThemes.Royale: uri = new Uri("PresentationFramework.Royale;V3.0.0.0;31bf3856ad364e35;component\\themes/Royale.NormalColor.xaml", UriKind.Relative); break; default: return; } Resources.MergedDictionaries.Add(LoadComponent(uri) as ResourceDictionary); }
public static void Initialize() { Theme = LoadThemeFromSettings(); }
public ThemePickerViewModel(IAnalyticsService analyticsService) : base(analyticsService) { SetAppThemeCommand = new AsyncCommand <AppThemeViewModel>((x) => SetAppTheme(x)); AppThemes.FirstOrDefault(x => x.Key == Settings.AppTheme).IsSelected = true; }