/// <summary> /// Gets the <see cref="Theme"/> with the given resource dictionary. /// </summary> /// <param name="resources"><see cref="ResourceDictionary"/> from which the theme should be retrieved.</param> /// <returns>The <see cref="Theme"/> or <c>null</c>, if the theme wasn't found.</returns> public static Theme GetTheme([NotNull] ResourceDictionary resources) { if (resources.IsNull()) { throw new ArgumentNullException(nameof(resources)); } var builtInTheme = Themes.FirstOrDefault(x => AreResourceDictionarySourcesEqual(x.Resources, resources)); if (builtInTheme.IsNotNull()) { return(builtInTheme); } // support dynamically created runtime resource dictionaries if (resources.Source.IsNull()) { if (IsThemeDictionary(resources)) { return(new Theme(resources)); } } return(null); }
public Task <bool> DeleteContentItem(string path) { var existingItem = ContentItems.FirstOrDefault(p => p.Path == path); if (existingItem != null) { Remove(existingItem); } var steps = path.Split('/'); if (steps.Length > 2) { var themePath = string.Join("/", steps[0], steps[1]); var theme = Themes.FirstOrDefault(t => t.Id == themePath); if (theme != null) { theme.ModifiedDate = DateTime.UtcNow; Update(theme); } } UnitOfWork.Commit(); return(Task.FromResult(true)); }
public ThemeWindowControlViewModel(Guid currentTheme) { Themes = new[] { new Theme { Name = "Dark", Guid = new Guid("{1DED0138-47CE-435E-84EF-9EC1F439B749}"), ResourceName = "Theme.Dark.vssettings" }, new Theme { Name = "Light", Guid = new Guid("{DE3DBBCD-F642-433C-8353-8F1DF4370ABA}"), ResourceName = "Theme.Light.vssettings" }, new Theme { Name = "Blue", Guid = new Guid("{A4D6A176-B948-4B29-8C66-53C97A1ED7D0}"), ResourceName = "Theme.Blue.vssettings" }, new Theme { Name = "Blue (Extra Contrast)", Guid = new Guid("{CE94D289-8481-498B-8CA9-9B6191A315B9}"), ResourceName = "Theme.BlueHighContrast.vssettings" } }; _selectedTheme = Themes.FirstOrDefault((x) => x.Guid.Equals(currentTheme)) ?? Themes[0]; }
public void Attach(IResourceNode node, IResourceDictionary resources, Action <ThemeViewModel> preview = null) { var defaultThem = GetTheme(node); defaultThem.Name = "BaseLight"; DefaultTheme = defaultThem; if (Themes == null) { CurrentTheme = defaultThem.Clone(); #pragma warning disable CS0618 Themes = new ReactiveList <ThemeViewModel>(); Themes.Add(CurrentTheme); #pragma warning restore CS0618 } else { CurrentTheme = Themes.FirstOrDefault(); } _themeObservable = ObserveTheme(resources, CurrentTheme, preview); _editorObservable = Changed.Subscribe(x => { if (x.PropertyName == nameof(CurrentTheme)) { _themeObservable?.Dispose(); if (CurrentTheme != null) { _themeObservable = ObserveTheme(resources, CurrentTheme, preview); } } }); }
public void Attach(IResourceDictionary resources, Action <ThemeViewModel>?preview = null) { if (Themes == null) { CurrentTheme = DefaultTheme?.Clone(); Themes = new ObservableCollection <ThemeViewModel>(); if (CurrentTheme != null) { Themes.Add(CurrentTheme); } } else { CurrentTheme = Themes.FirstOrDefault(); } if (CurrentTheme != null) { _themeObservable = ObserveTheme(resources, CurrentTheme, preview); _editorObservable = Changed.Subscribe(x => { if (x.PropertyName == nameof(CurrentTheme)) { _themeObservable?.Dispose(); if (CurrentTheme != null) { _themeObservable = ObserveTheme(resources, CurrentTheme, preview); } } }); } }
private void SyncThemeAndColor() { // synchronizes the selected viewmodel theme with the actual theme used by the appearance manager. SelectedTheme = Themes.FirstOrDefault(l => l.Source.Equals(AppearanceManager.Current.ThemeSource)); // and make sure accent color is up-to-date SelectedAccentColor = AppearanceManager.Current.AccentColor; }
private void InitializeAppSettings() { string selectedThemeName = null; try { selectedThemeName = AppSetting.Instance.ThemeName; if (string.IsNullOrEmpty(selectedThemeName)) { throw new Exception(); } } catch { selectedThemeName = DefaultThemeName; AppSetting.Instance.ThemeName = selectedThemeName; } SelectedTheme = Themes.FirstOrDefault( x => x.Name.Equals( selectedThemeName, StringComparison.OrdinalIgnoreCase)); SelectedPowerOption = AppSetting.Instance.PowerOption; Application.Current.Exit += (s, args) => { AppSetting.Instance.PowerOption = SelectedPowerOption; AppSetting.Instance.ThemeName = SelectedTheme.Name; AppSetting.SaveSettings(); }; }
protected virtual void ResetThemes() { try { var selectedThemeId = _selectedTheme.Id; ReloadThemeList(); foreach (Theme theme in Themes) { OnThemeUpdated(theme); } var originalSelection = Themes.FirstOrDefault(t => t.Id == selectedThemeId); if (originalSelection != null) { lstThemes.SelectedItem = originalSelection; } } catch (Exception ex) { ExceptionHandler("Error resetting themes", ex); } }
public ThemeSelectionPageViewModel(IThemeService themeService) { _themeService = themeService; var selectedTheme = Themes.FirstOrDefault(x => x.Theme == _themeService.CurrentTheme()); selectedTheme.IsSelected = true; }
public void RemoveTheme(ThemeViewModel theme) { if (Themes != null) { Themes.Remove(theme); CurrentTheme = Themes.FirstOrDefault(); } }
protected override void Initialize() { base.Initialize(); //Load Data from Option Service SelectedTabPlacement = ShellOptionService.TabStripPlacement; SelectedStyle = ShellOptionService.WindowStyle; SelectedTheme = Themes.FirstOrDefault(t => t.Name.EqualsIgnoreCase(ShellOptionService.Theme)); }
/// <summary> /// OnInitialized 方法 /// </summary> protected override void OnInitialized() { base.OnInitialized(); Title ??= Localizer[nameof(Title)]; HeaderText ??= Localizer[nameof(HeaderText)]; Themes = BootstrapOptions.CurrentValue.Themes.Select(kv => new SelectedItem(kv.Value, kv.Key)); SiteOptions.CurrentValue.CurrentTheme = Themes.FirstOrDefault(i => i.Text == "Motronic")?.Value ?? ""; }
public AppearanceOptionAreaViewModel(IUnityContainer container, ILocalConfigInfo localConfigInfo) : base(container) { _localConfigInfo = localConfigInfo; var temp = AppearanceManager.Current.AccentColor; SelectedTheme = Themes.FirstOrDefault(item => item.DisplayName == _localConfigInfo.Theme); SelectedPalette = temp; }
public Theme?GetTheme(string name, bool highContrast = false) { if (name is null) { throw new ArgumentNullException(nameof(name)); } return(Themes.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && x.IsHighContrast == highContrast)); }
public Boolean SetCurrentTheme(String name, Boolean applySetting) { try { // Find theme for name IMesTheme theme = Themes.FirstOrDefault(x => x.Name == name); if (theme == null) { return(false); } CurrentTheme = theme; // Setup asnc info Mvx.IoCProvider.Resolve <IMvxMainThreadAsyncDispatcher>() .ExecuteOnMainThreadAsync(() => { // Setup app style ResourceDictionary appTheme = Application.Current.Resources.MergedDictionaries.Count > 0 ? Application.Current.Resources.MergedDictionaries[0] : null; if (appTheme == null) { appTheme = new ResourceDictionary(); Application.Current.Resources.MergedDictionaries.Add(appTheme); } appTheme.BeginInit(); appTheme.MergedDictionaries.Clear(); foreach (Uri uri in theme.ApplicationResources) { ResourceDictionary newDict = new ResourceDictionary { Source = uri }; appTheme.MergedDictionaries.Add(newDict); } appTheme.EndInit(); }); _log.Info($"Theme set to {name}"); // publish event _messenger.Publish(new MesThemeChangeMessage(this, CurrentTheme.Name)); if (applySetting) { Properties.Settings.Default.ThemeName = CurrentTheme.Name; } return(true); } catch (Exception e) { _log.InfoException("Log Theme Setting", e); return(false); } }
/// <summary> /// Gets the <see cref="Theme"/> with the given name. /// </summary> /// <returns>The <see cref="Theme"/> or <c>null</c>, if the theme wasn't found</returns> public static Theme GetTheme([NotNull] string name) { if (name.IsNull()) { throw new ArgumentNullException(nameof(name)); } return(Themes.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// enables the theme for the window /// </summary> /// <param name="window"></param> public void EnableTheme(Window window) { IDisposable disposableForSelectedTheme = null; IDisposable disposableForSelectedBaseColor = null; window.Opened += (o, e) => { if (SelectedTheme == null) { SelectedTheme = Themes.FirstOrDefault(); } //ObserveOn(RxApp.MainThreadScheduler) disposableForSelectedTheme = this.WhenAnyValue(x => x.SelectedTheme).Where(x => x != null) .Subscribe(x => { var item = window.Styles.GetThemeStyle(); int index = window.Styles.GetThemeStyleIndex(item); var result = window.CheckAccess(); if (index == -1) { window.Styles.Add(x.ThemeStyle); } else { window.Styles.Remove(item); window.Styles.Add(x.ThemeStyle); } }); //ObserveOn(RxApp.MainThreadScheduler) disposableForSelectedBaseColor = this.WhenAnyValue(x => x.SelectedBaseColor).Where(x => x != null).Subscribe(selectedBaseColor => { var colorScheme = SelectedTheme?.ColorScheme ?? Themes.Select(x => x.ColorScheme) .FirstOrDefault(); SelectedTheme = Themes.FirstOrDefault(x => x.ColorScheme == colorScheme && x.BaseColorScheme == selectedBaseColor); }); if (registeredWindows.Contains(window) == false) { registeredWindows.Add(window); } }; window.Closing += (o, e) => { disposableForSelectedTheme?.Dispose(); disposableForSelectedBaseColor?.Dispose(); registeredWindows.Remove(window); }; }
// Behaviors public bool SetCurrentTheme(string name) { var theme = Themes.FirstOrDefault(t => t.Name == name); if (theme == null) { return(false); } CurrentTheme = theme; // add resource dictionary if not exist if (_applicationResourceDictionary == null) { _applicationResourceDictionary = new ResourceDictionary(); Application.Current.Resources.MergedDictionaries.Add(_applicationResourceDictionary); } // begin update application and window resources _applicationResourceDictionary.BeginInit(); _applicationResourceDictionary.MergedDictionaries.Clear(); // get window resource dictionary var windowResourceDictionary = Application.Current.MainWindow.Resources.MergedDictionaries[0]; windowResourceDictionary.BeginInit(); windowResourceDictionary.MergedDictionaries.Clear(); // load theme application resources foreach (var uri in theme.ApplicationResources) { _applicationResourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = uri }); } // load main window resources foreach (var uri in theme.MainWindowResources) { windowResourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = uri }); } // finish update _applicationResourceDictionary.EndInit(); windowResourceDictionary.EndInit(); // raise changed event CurrentThemeChanged?.Invoke(this, EventArgs.Empty); return(true); }
public void ChangeTheme(string themeName) { if (Themes != null) { var theme = Themes.FirstOrDefault(i => string.Equals(i.Name, themeName)); if (theme != null) { ChangeTheme(theme); } } }
private void GetSetting() { Log.Debug(String.Format("Get Setting")); RegistryKey subKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\MP\UI DEV\PrevSesParameters"); SelectedAccent = Accents.FirstOrDefault(e => e.Tag.ToString() == subKey.GetValue("Accent", "Lime").ToString()); SelectedTheme = Themes.FirstOrDefault(e => e == subKey.GetValue("AppTheme", "NIGHT").ToString()); SelectedLanguage = Languages.FirstOrDefault(l => l.Culture == subKey.GetValue("Language", "en").ToString()); subKey.Close(); }
public bool SetCurrentTheme(string name) { var theme = Themes.FirstOrDefault(x => x.Name == name); if (theme == null) { return(false); } var mainWindow = Application.Current.MainWindow; if (mainWindow == null) { return(false); } CurrentTheme = theme; if (_applicationResourceDictionary == null) { _applicationResourceDictionary = new ResourceDictionary(); Application.Current.Resources.MergedDictionaries.Add(_applicationResourceDictionary); } _applicationResourceDictionary.BeginInit(); _applicationResourceDictionary.MergedDictionaries.Clear(); var windowResourceDictionary = mainWindow.Resources.MergedDictionaries[0]; windowResourceDictionary.BeginInit(); windowResourceDictionary.MergedDictionaries.Clear(); foreach (var uri in theme.ApplicationResources) { _applicationResourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = uri }); } foreach (var uri in theme.MainWindowResources) { windowResourceDictionary.MergedDictionaries.Add(new ResourceDictionary { Source = uri }); } _applicationResourceDictionary.EndInit(); windowResourceDictionary.EndInit(); RaiseCurrentThemeChanged(EventArgs.Empty); return(true); }
private void SyncThemeAndColor() { // synchronizes the selected viewmodel theme with the actual theme used by the appearance manager. SelectedTheme = Themes.FirstOrDefault(l => l.Source.Equals(AppearanceManager.Current.ThemeSource)); // and make sure accent color is up-to-date SelectedAccentColor = AppearanceManager.Current.AccentColor; DataGetter.SaveConfig("R", AppearanceManager.Current.AccentColor.R.ToString()); DataGetter.SaveConfig("A", AppearanceManager.Current.AccentColor.A.ToString()); DataGetter.SaveConfig("G", AppearanceManager.Current.AccentColor.G.ToString()); DataGetter.SaveConfig("B", AppearanceManager.Current.AccentColor.B.ToString()); }
public static Theme ChangeTheme([NotNull] ResourceDictionary resources, Theme oldTheme, [NotNull] string baseColor, [NotNull] string colorScheme) { var newTheme = Themes.FirstOrDefault(x => x.BaseColorScheme == baseColor && x.ColorScheme == colorScheme); if (newTheme.IsNull()) { Trace.TraceError($"Could not find a theme with base color scheme '{baseColor}' and color scheme '{oldTheme.ColorScheme}'."); return(null); } return(ChangeTheme(resources, oldTheme, newTheme)); }
private void SyncThemeAndColor() { //SelectedAccentColor = (Color)ColorConverter.ConvertFromString(Properties.Appearance.Default.selectedAccentColor); SelectedFontSize = Properties.Appearance.Default.selectedFontSize; SelectedPalette = Properties.Appearance.Default.selectedPalette; SelectedTheme = Themes.FirstOrDefault(x => x.DisplayName == Properties.Appearance.Default.selectedTheme); //// synchronizes the selected viewmodel theme with the actual theme used by the appearance manager. //this.SelectedTheme = this.themes.FirstOrDefault(l => l.Source.Equals(AppearanceManager.Current.ThemeSource)); //// and make sure accent color is up-to-date //this.SelectedAccentColor = AppearanceManager.Current.AccentColor; }
public static void SetTheme(KYUITheme newTheme, Application currentApp) { var newThemeName = newTheme.ToString(); if (!_themeNames.Contains(newThemeName)) { throw new ArgumentException("Theme was not found."); } var theme = Themes.FirstOrDefault(t => t.Name == newThemeName); currentApp.Styles.RemoveAll(Themes.Select(t => t.Style)); currentApp.Styles.Add(theme.Style); }
public Theme?GetTheme(ResourceDictionary resourceDictionary) { if (resourceDictionary is null) { throw new ArgumentNullException(nameof(resourceDictionary)); } var themeInstance = Theme.GetThemeInstance(resourceDictionary); if (themeInstance is not null) { return(themeInstance); } var builtInTheme = Themes.FirstOrDefault(x => x.Name == Theme.GetThemeName(resourceDictionary)); if (builtInTheme is not null) { return(builtInTheme); } // support dynamically created runtime resource dictionaries if (IsRuntimeGeneratedThemeDictionary(resourceDictionary)) { foreach (var resourceDictionaryKey in resourceDictionary.Keys) { if (Theme.ThemeInstanceKey.Equals(resourceDictionaryKey)) { return((Theme)resourceDictionary[resourceDictionaryKey]); } } foreach (var resourceDictionaryKey in resourceDictionary.Keys) { if (LibraryTheme.LibraryThemeInstanceKey.Equals(resourceDictionaryKey)) { var parentTheme = ((LibraryTheme)resourceDictionary[resourceDictionaryKey]).ParentTheme; if (parentTheme is not null) { return(parentTheme); } } } return(new Theme(new LibraryTheme(resourceDictionary, null))); } return(null); }
public void LoadThemes() { var themes = repository.GetAllThemes(); SelectedTheme = null; Themes.Clear(); foreach (var kv in themes.OrderBy(t => t.Value)) { Themes.Add(new ThemeInfos { Title = kv.Value, File = kv.Key }); } SelectedTheme = Themes.FirstOrDefault(); }
public void Load() { Themes = ThemeHelper.GetAvailableThemes() .Select(t => new SelectableVM <Theme>(t)) .ToList(); var settings = SettingsHelper.GetSettings(); SelectedTheme = Themes.FirstOrDefault(t => t.Data.Name.Equals(settings.Theme, System.StringComparison.OrdinalIgnoreCase)) ?? Themes.First(); DefaultOverwritePasses = settings.DefaultOverwritePasses; _isLoaded = true; }
public void DeleteTheme(string path) { var existingTheme = Themes.FirstOrDefault(t => t.Id == path); if (existingTheme != null) { Remove(existingTheme); var contentItems = ContentItems.Where(c => c.Path.StartsWith(path)); foreach (var item in contentItems) { Remove(item); } UnitOfWork.Commit(); } }
protected void ChangeTheme(object theme) { Uri uri; if ((string)theme == null) { _currentTheme = Themes[0]; uri = new Uri(Themes[0].Path, UriKind.Relative); } else { _currentTheme = Themes.FirstOrDefault(t => t.Path == (string)theme); uri = new Uri((string)theme, UriKind.Relative); } ChangeTheme(uri); }