public override void Initialize(IConfig config) { // Prepare disposables _disposables?.Dispose(); _disposables = new CompositeDisposable(); AvailableThemeAccents.Clear(); foreach (var themeAccent in Enum.GetValues(typeof(ThemeAccents)).Cast <ThemeAccents>()) { var translation = themeAccent.EnumValueOf(); AvailableThemeAccents.Add(new Tuple <ThemeAccents, string>(themeAccent, translation)); } AvailableThemes.Clear(); foreach (var theme in Enum.GetValues(typeof(Themes)).Cast <Themes>()) { var translation = theme.EnumValueOf(); AvailableThemes.Add(new Tuple <Themes, string>(theme, translation)); } // Place this under the Ui parent ParentId = "Ui"; // Make sure Commit/Rollback is called on the UiConfiguration config.Register(MetroConfiguration); // automatically update the DisplayName _disposables.Add(UiTranslations.CreateDisplayNameBinding(this, nameof(IUiTranslations.Theme))); base.Initialize(config); }
private static void LoadTheme(string themeName) { var resourcesToLoad = new List <Uri>(3) { new Uri($"pack://application:,,,/Nodify;component/Themes/{themeName}.xaml"), new Uri($"pack://application:,,,/Nodify.Shared;component/Themes/{themeName}.xaml") }; var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name; if (assemblyName != null) { resourcesToLoad.Add(new Uri($"pack://application:,,,/{assemblyName};component/Themes/{themeName}.xaml")); } foreach (var theme in resourcesToLoad) { try { var resource = new ThemeDictionary { Source = theme, ThemeName = themeName }; Application.Current.Resources.MergedDictionaries.Add(resource); } catch { } } ActiveTheme = themeName; AvailableThemes.Add(themeName); }
public override void Initialize(IConfig config) { // Prepare disposables _disposables?.Dispose(); _disposables = new CompositeDisposable(); AvailableThemeAccents.Clear(); foreach (var themeAccent in Enum.GetValues(typeof(ThemeAccents)).Cast <ThemeAccents>()) { var translation = themeAccent.EnumValueOf(); AvailableThemeAccents.Add(new Tuple <ThemeAccents, string>(themeAccent, translation)); } AvailableThemes.Clear(); foreach (var theme in Enum.GetValues(typeof(Themes)).Cast <Themes>()) { var translation = theme.EnumValueOf(); AvailableThemes.Add(new Tuple <Themes, string>(theme, translation)); } // Place this under the Ui parent ParentId = nameof(ConfigIds.Ui); // Make sure Commit/Rollback is called on the IUiConfiguration config.Register(MetroConfiguration); // automatically update the DisplayName var greenshotLanguageBinding = GreenshotLanguage.CreateDisplayNameBinding(this, nameof(IGreenshotLanguage.SettingsTitle)); // Make sure the greenshotLanguageBinding is disposed when this is no longer active _disposables.Add(greenshotLanguageBinding); base.Initialize(config); }
/// <inheritdoc /> public override void Initialize(IConfig config) { // Prepare disposables _disposables?.Dispose(); _disposables = new CompositeDisposable(); AvailableThemes.Clear(); foreach (var theme in MetroThemeManager.AvailableThemes) { AvailableThemes.Add(theme); } foreach (var themeColor in MetroThemeManager.AvailableThemeColors) { AvailableThemeColors.Add(themeColor); } // Place this under the Ui parent ParentId = "Ui"; // Make sure Commit/Rollback is called on the UiConfiguration config.Register(MetroConfiguration); // automatically update the DisplayName _disposables.Add(UiTranslations.CreateDisplayNameBinding(this, nameof(IUiTranslations.Theme))); // Automatically show theme changes _disposables.Add( MetroConfiguration.OnPropertyChanging(nameof(MetroConfiguration.Theme)).Subscribe(args => { if (args is PropertyChangingEventArgsEx propertyChangingEventArgsEx) { _metroThemeManager.ChangeTheme(propertyChangingEventArgsEx.NewValue as string, null); } }) ); _disposables.Add( MetroConfiguration.OnPropertyChanging(nameof(MetroConfiguration.ThemeColor)).Subscribe(args => { if (args is PropertyChangingEventArgsEx propertyChangingEventArgsEx) { _metroThemeManager.ChangeTheme(null, propertyChangingEventArgsEx.NewValue as string); } }) ); base.Initialize(config); }
public async Task ReloadThemes() { IsLoading = true; var availableThemes = new List <Theme>(); var selectedThemeNames = App.LocalSettings.Read("SelectedThemeNames", new List <string>()); var availableThemeNames = App.LocalSettings.Read("AvailableThemeNames", new List <string>()); var themeDirectory = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Themes", CreationCollisionOption.OpenIfExists); var directories = await themeDirectory.GetFoldersAsync(); foreach (var directory in directories) { if (await directory.TryGetItemAsync("theme.json") is StorageFile themeJson) { try { var theme = JsonConvert.DeserializeObject <Theme>(await FileIO.ReadTextAsync(themeJson)); availableThemes.Add(theme); if (!availableThemeNames.Contains(theme.NormalisedName)) { availableThemeNames.Add(theme.NormalisedName); } } catch { } } } AvailableThemes.Clear(); foreach (var theme in availableThemes.OrderBy(t => availableThemeNames.IndexOf(t.NormalisedName))) { AvailableThemes.Add(theme); } SelectedThemes.Clear(); foreach (var theme in availableThemes.Where(t => selectedThemeNames.Contains(t.NormalisedName))) { SelectedThemes.Add(theme); } IsLoading = false; InvokePropertyChanged(nameof(ShowThemesPlaceholder)); App.LocalSettings.Save("AvailableThemeNames", availableThemeNames); }