private void InitializeThemes() { List <Mubox.View.Themes.ThemeDescriptor> themesList = new List <Mubox.View.Themes.ThemeDescriptor>(); AddThemeResource(themesList, "Default"); AddThemeResource(themesList, "Black"); AddThemeResource(themesList, "Orange"); AddThemeResource(themesList, "Brown"); AddThemeResource(themesList, "Red"); AddThemeResource(themesList, "Green"); AddThemeResource(themesList, "Blue"); AddThemeResource(themesList, "ExtraLife"); comboThemeSelector.SelectionChanged += (L_sender, L_e) => { Mubox.View.Themes.ThemeDescriptor theme = (comboThemeSelector.SelectedItem as Mubox.View.Themes.ThemeDescriptor); if (Application.Current.Resources.MergedDictionaries.Count > 0) { Application.Current.Resources.MergedDictionaries.Clear(); } if (theme != null) { Application.Current.Resources.MergedDictionaries.Add(theme.Resources); Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme = theme.Name; } else { Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme = "Default"; } Mubox.Configuration.MuboxConfigSection.Default.Save(); }; comboThemeSelector.ItemsSource = themesList; comboThemeSelector.DisplayMemberPath = "Name"; }
private void AddThemeResource(List <Mubox.View.Themes.ThemeDescriptor> themesList, string themeName) { try { var uri = new Uri("pack://siteoforigin:,,,/View/Themes/" + themeName + ".xaml", UriKind.Absolute); var resourceInfo = Application.GetRemoteStream(uri); var reader = new System.Windows.Markup.XamlReader(); ResourceDictionary resourceDictionary = (ResourceDictionary)reader.LoadAsync(resourceInfo.Stream); Mubox.View.Themes.ThemeDescriptor theme = new Mubox.View.Themes.ThemeDescriptor { Name = themeName, Resources = resourceDictionary }; themesList.Add(theme); if (Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme == themeName) { Application.Current.Resources.MergedDictionaries.Add(theme.Resources); comboThemeSelector.SelectedItem = theme; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } }
private void AddThemeResource(List<Mubox.View.Themes.ThemeDescriptor> themesList, string themeName) { try { var uri = new Uri("pack://siteoforigin:,,,/View/Themes/" + themeName + ".xaml", UriKind.Absolute); var resourceInfo = Application.GetRemoteStream(uri); var reader = new System.Windows.Markup.XamlReader(); ResourceDictionary resourceDictionary = (ResourceDictionary)reader.LoadAsync(resourceInfo.Stream); Mubox.View.Themes.ThemeDescriptor theme = new Mubox.View.Themes.ThemeDescriptor { Name = themeName, Resources = resourceDictionary }; themesList.Add(theme); if (Mubox.Configuration.MuboxConfigSection.Default.PreferredTheme == themeName) { Application.Current.Resources.MergedDictionaries.Add(theme.Resources); comboThemeSelector.SelectedItem = theme; } } catch (Exception ex) { ex.Log(); } }