diff --git a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs index 2e8f0b1750..7474254302 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs +++ b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -4678,6 +4677,15 @@ public static string HelpMessage_ThreadPoolAdditionalMinThreads { } } + /// + /// Looks up a localized string similar to Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation.. + /// + public static string HelpMessage_UseCustomThemes { + get { + return ResourceManager.GetString("HelpMessage_UseCustomThemes", resourceCulture); + } + } + /// /// Looks up a localized string similar to Hidden applications. /// diff --git a/Source/NETworkManager.Localization/Resources/Strings.cs-CZ.resx b/Source/NETworkManager.Localization/Resources/Strings.cs-CZ.resx index 540ffbd449..1bfacd0165 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.cs-CZ.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.cs-CZ.resx @@ -3993,4 +3993,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.de-DE.resx b/Source/NETworkManager.Localization/Resources/Strings.de-DE.resx index 0d05689c74..ba5f610aaf 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.de-DE.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.de-DE.resx @@ -3993,4 +3993,7 @@ Rechtsklick für weitere Optionen. Alle einklappen + + Verwenden Sie benutzerdefinierte Themes, um das Erscheinungsbild der Anwendung anzupassen. Sie können Themes im Verzeichnis „Program Folder > Themes“ bearbeiten oder hinzufügen. Weitere Informationen finden Sie in der Dokumentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.es-ES.resx b/Source/NETworkManager.Localization/Resources/Strings.es-ES.resx index 323c1367c3..de27a3929a 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.es-ES.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.es-ES.resx @@ -3990,4 +3990,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.fr-FR.resx b/Source/NETworkManager.Localization/Resources/Strings.fr-FR.resx index 36ca0fa322..2dd9c7f5b6 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.fr-FR.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.fr-FR.resx @@ -3993,4 +3993,7 @@ Clic droit pour plus d'options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.hu-HU.resx b/Source/NETworkManager.Localization/Resources/Strings.hu-HU.resx index f9ef6c7375..5b7ff230f1 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.hu-HU.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.hu-HU.resx @@ -3993,4 +3993,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.it-IT.resx b/Source/NETworkManager.Localization/Resources/Strings.it-IT.resx index ac0bc3246c..db708be3f1 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.it-IT.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.it-IT.resx @@ -4096,4 +4096,7 @@ Per maggiori dettagli consulta il file registro. Riduci tutto + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.ja-JP.resx b/Source/NETworkManager.Localization/Resources/Strings.ja-JP.resx index b66bfd975e..54a30b2421 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.ja-JP.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.ja-JP.resx @@ -3993,4 +3993,7 @@ Open Windows Settings > Privacy & security > Location, enable access f Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.ko-KR.resx b/Source/NETworkManager.Localization/Resources/Strings.ko-KR.resx index 37fc3d4c2f..c297541b0d 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.ko-KR.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.ko-KR.resx @@ -3990,4 +3990,7 @@ Open Windows Settings > Privacy & security > Location, enable access f Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.nl-NL.resx b/Source/NETworkManager.Localization/Resources/Strings.nl-NL.resx index 5a86d649a4..80a97f3a4c 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.nl-NL.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.nl-NL.resx @@ -3990,4 +3990,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.pl-PL.resx b/Source/NETworkManager.Localization/Resources/Strings.pl-PL.resx index 91d02537be..2c830a7853 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.pl-PL.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.pl-PL.resx @@ -3990,4 +3990,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.pt-BR.resx b/Source/NETworkManager.Localization/Resources/Strings.pt-BR.resx index 99ca72c65a..d8955f3619 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.pt-BR.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.pt-BR.resx @@ -3993,4 +3993,7 @@ Clique direito para mais opções. Fechar todos + + Use temas personalizados para personalizar a aparência do aplicativo. Você pode editar ou adicionar temas na pasta "Temas" dentro da pasta do programa. Para mais detalhes, consulte a documentação. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.resx b/Source/NETworkManager.Localization/Resources/Strings.resx index d88ec26a51..56be8078c4 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.resx @@ -3993,4 +3993,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + \ No newline at end of file diff --git a/Source/NETworkManager.Localization/Resources/Strings.ru-RU.resx b/Source/NETworkManager.Localization/Resources/Strings.ru-RU.resx index 40c758fe1c..53284b8642 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.ru-RU.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.ru-RU.resx @@ -3993,4 +3993,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.sl-SI.resx b/Source/NETworkManager.Localization/Resources/Strings.sl-SI.resx index f64d2cea6a..c5fb397d51 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.sl-SI.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.sl-SI.resx @@ -3975,4 +3975,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.sv-SE.resx b/Source/NETworkManager.Localization/Resources/Strings.sv-SE.resx index 581a022777..373593d428 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.sv-SE.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.sv-SE.resx @@ -3990,4 +3990,7 @@ Right-click for more options. Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.zh-CN.resx b/Source/NETworkManager.Localization/Resources/Strings.zh-CN.resx index 3c08f1faae..6040b37928 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.zh-CN.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.zh-CN.resx @@ -3994,4 +3994,7 @@ Open Windows Settings > Privacy & security > Location, enable access f Collapse all + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Localization/Resources/Strings.zh-TW.resx b/Source/NETworkManager.Localization/Resources/Strings.zh-TW.resx index 8fd247f67c..81bb63741c 100644 --- a/Source/NETworkManager.Localization/Resources/Strings.zh-TW.resx +++ b/Source/NETworkManager.Localization/Resources/Strings.zh-TW.resx @@ -3992,4 +3992,7 @@ $$hostname$$ --> 主機名稱 全部摺疊 + + Use custom themes to personalize the appearance of the application. You can edit or add theme in the "Program Folder > Themes" directory. For more details, refer to the documentation. + diff --git a/Source/NETworkManager.Settings/AppearanceManager.cs b/Source/NETworkManager.Settings/AppearanceManager.cs index 7d2ef686a9..5887c0c70e 100644 --- a/Source/NETworkManager.Settings/AppearanceManager.cs +++ b/Source/NETworkManager.Settings/AppearanceManager.cs @@ -1,13 +1,13 @@ -using System; +using ControlzEx.Theming; +using MahApps.Metro.Controls.Dialogs; +using MahApps.Metro.Theming; +using NETworkManager.Models.Appearance; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows; using System.Windows.Media; -using ControlzEx.Theming; -using MahApps.Metro.Controls.Dialogs; -using MahApps.Metro.Theming; -using NETworkManager.Models.Appearance; namespace NETworkManager.Settings; @@ -16,6 +16,27 @@ namespace NETworkManager.Settings; /// public static class AppearanceManager { + #region Variables + /// + /// Dictionary to override some brushes for the light theme. + /// + private static readonly ResourceDictionary LightThemeOverrideDictionary = new() + { + //["MahApps.Brushes.ThemeBackground"] = new SolidColorBrush(Color.FromRgb(248, 248, 255)), + //["MahApps.Brushes.Control.Background"] = new SolidColorBrush(Color.FromRgb(248, 248, 255)), + ["MahApps.Brushes.Gray3"] = new SolidColorBrush(Color.FromRgb(104, 104, 104)), + ["MahApps.Brushes.Gray5"] = new SolidColorBrush(Color.FromRgb(138, 138, 138)), + ["MahApps.Brushes.Gray8"] = new SolidColorBrush(Color.FromRgb(190, 190, 190)), + }; + + /// + /// Dictionary to override some brushes for the dark theme. + /// + private static readonly ResourceDictionary DarkThemeOverrideDictionary = new() + { + + }; + /// /// Name of the folder inside the application directory where the custom themes are stored. /// @@ -26,23 +47,40 @@ public static class AppearanceManager /// public static readonly MetroDialogSettings MetroDialog = new(); + /// + /// List who contains all MahApps.Metro themes. + /// + public static List Themes { get; set; } + + /// + /// List who contains all MahApps.Metro custom themes. + /// + public static List CustomThemes { get; private set; } + + /// + /// List who contains all MahApps.Metro accents. + /// + public static List Accents { get; set; } + #endregion + + #region Constructor /// /// Load the MahApps.Metro themes and accents when needed. /// static AppearanceManager() { - Themes = ThemeManager.Current.Themes + Themes = [.. ThemeManager.Current.Themes .GroupBy(x => x.BaseColorScheme) .Select(x => x.First()) .Select(x => new ThemeColorInfo - { Name = x.BaseColorScheme, Color = x.Resources["MahApps.Brushes.ThemeBackground"] as Brush }) - .ToList(); + { Name = x.BaseColorScheme, Color = x.Resources["MahApps.Brushes.ThemeBackground"] as Brush })]; - Accents = ThemeManager.Current.Themes + Accents = [.. ThemeManager.Current.Themes .GroupBy(x => x.ColorScheme) .OrderBy(x => x.Key) - .Select(x => new AccentColorInfo { Name = x.Key, Color = x.First().ShowcaseBrush }) - .ToList(); + .Select(x => new AccentColorInfo { Name = x.Key, Color = x.First().ShowcaseBrush })]; + + ThemeManager.Current.ThemeChanged += Current_ThemeChanged; LoadCustomThemes(); @@ -55,22 +93,9 @@ static AppearanceManager() MetroDialog.DialogButtonFontSize = 14; MetroDialog.DialogMessageFontSize = 14; } + #endregion - /// - /// List who contains all MahApps.Metro themes. - /// - public static List Themes { get; set; } - - /// - /// List who contains all MahApps.Metro custom themes. - /// - public static List CustomThemes { get; private set; } - - /// - /// List who contains all MahApps.Metro accents. - /// - public static List Accents { get; set; } - + #region Methods /// /// Change the appearance based on the user settings. This method should be called once, when starting the application. /// @@ -79,14 +104,13 @@ public static void Load() if (SettingsManager.Current.Appearance_UseCustomTheme && CustomThemes.Count > 0) { ChangeTheme( - CustomThemes.FirstOrDefault(x => x.Name == SettingsManager.Current.Appearance_CustomThemeName) ?? - CustomThemes.First()); - } - else - { - ChangeTheme(SettingsManager.Current.Appearance_Theme); - ChangeAccent(SettingsManager.Current.Appearance_Accent); + (CustomThemes.FirstOrDefault(x => x.Name == SettingsManager.Current.Appearance_CustomThemeName) ?? + CustomThemes.First()).Name); + + return; } + + ChangeTheme(SettingsManager.Current.Appearance_Theme, SettingsManager.Current.Appearance_Accent); } /// @@ -94,7 +118,7 @@ public static void Load() /// private static void LoadCustomThemes() { - List customThemes = new(); + List customThemes = []; foreach (var file in Directory.GetFiles(Path.Combine(ConfigurationManager.Current.ExecutionPath, ThemeFolderName))) @@ -110,29 +134,68 @@ private static void LoadCustomThemes() } /// - /// Method to change the application theme. + /// Method to change the application theme (and accent). /// - /// Name of the MahApps theme base color. + /// Theme name as "theme.accent" to apply. public static void ChangeTheme(string name) { - ThemeManager.Current.ChangeThemeBaseColor(System.Windows.Application.Current, name); + ThemeManager.Current.ChangeTheme(System.Windows.Application.Current, name); } /// - /// Method to change the application accent. + /// Method to change the application theme (and accent). /// - /// Name of the MahApps theme accent color. - public static void ChangeAccent(string name) + /// Theme name to apply. + /// Accent name to apply. + public static void ChangeTheme(string theme, string accent) { - ThemeManager.Current.ChangeThemeColorScheme(System.Windows.Application.Current, name); + ChangeTheme($"{theme}.{accent}"); } /// - /// Method to change the application theme based on the name in . + /// /// - /// Theme as to apply. - public static void ChangeTheme(ThemeInfo themeInfo) + /// + private static void ApplyCustomThemeFixes(string theme) + { + // Don't apply on custom themes (only built-in light/dark themes) + if (CustomThemes.Any(x => x.Name.Equals(theme, StringComparison.OrdinalIgnoreCase))) + return; + + // Get application resources + var appResources = System.Windows.Application.Current.Resources; + + // Remove any existing theme overrides + appResources.MergedDictionaries.Remove(LightThemeOverrideDictionary); + appResources.MergedDictionaries.Remove(DarkThemeOverrideDictionary); + + + // Theme name is in format "theme.accent" + switch (theme.ToLowerInvariant().Split('.')[0]) + { + case "light": + appResources.MergedDictionaries.Add(LightThemeOverrideDictionary); + break; + + case "dark": + appResources.MergedDictionaries.Add(DarkThemeOverrideDictionary); + break; + } + + // Refresh UI + foreach (Window window in System.Windows.Application.Current.Windows) + { + if (window.IsLoaded) + window.InvalidateVisual(); + } + } + + #endregion + + #region Events + private static void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) { - ThemeManager.Current.ChangeTheme(System.Windows.Application.Current, themeInfo.Name); + ApplyCustomThemeFixes(e.NewTheme.Name); } -} \ No newline at end of file + #endregion +} diff --git a/Source/NETworkManager/Resources/Styles/TextBlockStyles.xaml b/Source/NETworkManager/Resources/Styles/TextBlockStyles.xaml index 886e024a66..a2b2fd109d 100644 --- a/Source/NETworkManager/Resources/Styles/TextBlockStyles.xaml +++ b/Source/NETworkManager/Resources/Styles/TextBlockStyles.xaml @@ -7,7 +7,7 @@ diff --git a/Source/NETworkManager/ViewModels/SettingsAppearanceViewModel.cs b/Source/NETworkManager/ViewModels/SettingsAppearanceViewModel.cs index 35a44b5f96..cd82cf16af 100644 --- a/Source/NETworkManager/ViewModels/SettingsAppearanceViewModel.cs +++ b/Source/NETworkManager/ViewModels/SettingsAppearanceViewModel.cs @@ -1,8 +1,8 @@ -using System.ComponentModel; +using NETworkManager.Models.Appearance; +using NETworkManager.Settings; +using System.ComponentModel; using System.Linq; using System.Windows.Data; -using NETworkManager.Models.Appearance; -using NETworkManager.Settings; namespace NETworkManager.ViewModels; @@ -26,7 +26,7 @@ public ThemeColorInfo SelectedTheme if (!_isLoading && !UseCustomTheme) { - AppearanceManager.ChangeTheme(value.Name); + AppearanceManager.ChangeTheme(value.Name, SelectedAccent.Name); SettingsManager.Current.Appearance_Theme = value.Name; } @@ -35,7 +35,6 @@ public ThemeColorInfo SelectedTheme } } - public ICollectionView Accents { get; } private AccentColorInfo _selectedAccent; @@ -50,7 +49,7 @@ public AccentColorInfo SelectedAccent if (!_isLoading && !UseCustomTheme) { - AppearanceManager.ChangeAccent(value.Name); + AppearanceManager.ChangeTheme(SelectedTheme.Name, value.Name); SettingsManager.Current.Appearance_Accent = value.Name; } @@ -95,7 +94,7 @@ public ThemeInfo SelectedCustomTheme if (!_isLoading && UseCustomTheme) { - AppearanceManager.ChangeTheme(value); + AppearanceManager.ChangeTheme(value.Name); SettingsManager.Current.Appearance_CustomThemeName = value.Name; } diff --git a/Source/NETworkManager/Views/SettingsAppearanceView.xaml b/Source/NETworkManager/Views/SettingsAppearanceView.xaml index c39767c5a3..cb301b42ec 100644 --- a/Source/NETworkManager/Views/SettingsAppearanceView.xaml +++ b/Source/NETworkManager/Views/SettingsAppearanceView.xaml @@ -15,15 +15,15 @@ - - + + ToolTip="{Binding Name, Converter={StaticResource ResourceKey=ThemeToStringConverter}}" /> @@ -39,15 +39,15 @@ - - + - + @@ -63,26 +63,34 @@ - - - + + + + + +