From 92a46ee169c98ca59e65a55b2872749248dee29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Sun, 10 Dec 2023 12:32:18 +0100 Subject: [PATCH] Fixed tab color issue when changing theme (#353) --- ColorPicker/Classes/Global.cs | 11 ++++++++++- ColorPicker/Pages/AiGenPage.xaml.cs | 6 +++++- ColorPicker/Pages/BookmarksPage.xaml.cs | 3 ++- ColorPicker/Pages/ChromaticWheelPage.xaml.cs | 3 ++- ColorPicker/Pages/ConverterPage.xaml.cs | 4 ++-- ColorPicker/Pages/HarmoniesPage.xaml.cs | 4 ++-- ColorPicker/Pages/PalettePage.xaml.cs | 5 ++--- ColorPicker/Pages/SettingsPage.xaml.cs | 6 +++--- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/ColorPicker/Classes/Global.cs b/ColorPicker/Classes/Global.cs index ceeeec81..d49c1226 100644 --- a/ColorPicker/Classes/Global.cs +++ b/ColorPicker/Classes/Global.cs @@ -31,6 +31,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using Synethia; using System; using System.Collections.Generic; +using System.ComponentModel.Design.Serialization; using System.Linq; using System.Threading; using System.Windows; @@ -254,7 +255,7 @@ public static AppPages PageInfoToAppPages(PageInfo pageInfo) /// /// Changes the application's theme. /// - public static void ChangeTheme() + public static void ChangeTheme(bool reload = false) { App.Current.Resources.MergedDictionaries.Clear(); ResourceDictionary resourceDictionary = new(); // Create a resource dictionary @@ -275,6 +276,14 @@ public static void ChangeTheme() } App.Current.Resources.MergedDictionaries.Add(resourceDictionary); // Add the dictionary + + if (!reload) return; + AiGenPage.CheckButton(AiGenPage.CheckedButton); + BookmarksPage.CheckButton(BookmarksPage.CheckedButton); + ConverterPage.CheckButton(ConverterPage.SelectedColorBtn); + ChromaticWheelPage.CheckButton(ChromaticWheelPage.CheckedButton); + HarmoniesPage.CheckButton(HarmoniesPage.SelectedColorBtn); + PalettePage.CheckButton(PalettePage.SelectedColorBtn); } public static bool IsSystemThemeDark() diff --git a/ColorPicker/Pages/AiGenPage.xaml.cs b/ColorPicker/Pages/AiGenPage.xaml.cs index 15cb16f4..4ddf9bf2 100644 --- a/ColorPicker/Pages/AiGenPage.xaml.cs +++ b/ColorPicker/Pages/AiGenPage.xaml.cs @@ -59,6 +59,7 @@ private void InitUI() if (!string.IsNullOrEmpty(Global.Settings.ApiKey)) { CheckButton(ColorBtn); + CheckedButton = ColorBtn; ColorPanel.Visibility = Visibility.Visible; ApiPlaceholder.Visibility = Visibility.Collapsed; return; @@ -202,7 +203,8 @@ private async void GenerateBtn_Click(object sender, RoutedEventArgs e) catch { } } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal Button CheckedButton; + internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); private void UnCheckAllButtons() { @@ -218,6 +220,7 @@ private void ColorBtn_Click(object sender, RoutedEventArgs e) if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return; UnCheckAllButtons(); CheckButton(ColorBtn); + CheckedButton = ColorBtn; ColorPanel.Visibility = Visibility.Visible; } @@ -226,6 +229,7 @@ private void PaletteBtn_Click(object sender, RoutedEventArgs e) if (string.IsNullOrEmpty(Global.Settings.ApiKey)) return; UnCheckAllButtons(); CheckButton(PaletteBtn); + CheckedButton = PaletteBtn; PalettePanel.Visibility = Visibility.Visible; } diff --git a/ColorPicker/Pages/BookmarksPage.xaml.cs b/ColorPicker/Pages/BookmarksPage.xaml.cs index 65fb8f34..e8a0b23d 100644 --- a/ColorPicker/Pages/BookmarksPage.xaml.cs +++ b/ColorPicker/Pages/BookmarksPage.xaml.cs @@ -139,7 +139,8 @@ private void UnCheckAllButtons() TextBookmarks.Visibility = Visibility.Collapsed; } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal Button CheckedButton; + internal void CheckButton(Button button) { button.Background = Global.GetColorFromResource("LightAccentColor"); CheckedButton = button; } private void TextBtn_Click(object sender, RoutedEventArgs e) { diff --git a/ColorPicker/Pages/ChromaticWheelPage.xaml.cs b/ColorPicker/Pages/ChromaticWheelPage.xaml.cs index 0fd39488..e0217ab8 100644 --- a/ColorPicker/Pages/ChromaticWheelPage.xaml.cs +++ b/ColorPicker/Pages/ChromaticWheelPage.xaml.cs @@ -126,7 +126,8 @@ private void UnCheckAllButtons() ShadesBtn.Background = new SolidColorBrush { Color = Colors.Transparent }; } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal Button CheckedButton; + internal void CheckButton(Button button) { button.Background = Global.GetColorFromResource("LightAccentColor"); CheckedButton = button; } private void CopyYiqBtn_Click(object sender, RoutedEventArgs e) { diff --git a/ColorPicker/Pages/ConverterPage.xaml.cs b/ColorPicker/Pages/ConverterPage.xaml.cs index 5bb12728..5f6ad074 100644 --- a/ColorPicker/Pages/ConverterPage.xaml.cs +++ b/ColorPicker/Pages/ConverterPage.xaml.cs @@ -75,7 +75,7 @@ private void InitUI() }, null); } - Button SelectedColorBtn { get; set; } + internal Button SelectedColorBtn { get; set; } private void UnCheckAllButtons() { RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent }; @@ -100,7 +100,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e) LoadInputUI(); } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); internal ColorInfo ColorInfo { get; set; } private RGB ConvertToRgb() diff --git a/ColorPicker/Pages/HarmoniesPage.xaml.cs b/ColorPicker/Pages/HarmoniesPage.xaml.cs index 61c4d76d..4a16de37 100644 --- a/ColorPicker/Pages/HarmoniesPage.xaml.cs +++ b/ColorPicker/Pages/HarmoniesPage.xaml.cs @@ -221,7 +221,7 @@ private RGB ConvertToRgb() double.Parse(Txt3.Text))); } - Button SelectedColorBtn { get; set; } + internal Button SelectedColorBtn { get; set; } private void UnCheckAllButtons() { RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent }; @@ -247,7 +247,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e) Global.SynethiaConfig.PagesInfo[7].InteractionCount++; } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); private void HideAllInput() { diff --git a/ColorPicker/Pages/PalettePage.xaml.cs b/ColorPicker/Pages/PalettePage.xaml.cs index 57cf9bcf..ad8ab083 100644 --- a/ColorPicker/Pages/PalettePage.xaml.cs +++ b/ColorPicker/Pages/PalettePage.xaml.cs @@ -26,7 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using ColorPicker.Enums; using ColorPicker.Windows; using Synethia; -using System.Security.Cryptography; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -103,7 +102,7 @@ private RGB ConvertToRgb() double.Parse(Txt3.Text))); } - Button SelectedColorBtn { get; set; } + internal Button SelectedColorBtn { get; set; } private void UnCheckAllButtons() { RgbBtn.Background = new SolidColorBrush { Color = Colors.Transparent }; @@ -128,7 +127,7 @@ internal void RgbBtn_Click(object sender, RoutedEventArgs? e) LoadInputUI(); } - private void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); + internal void CheckButton(Button button) => button.Background = Global.GetColorFromResource("LightAccentColor"); private void HideAllInput() { diff --git a/ColorPicker/Pages/SettingsPage.xaml.cs b/ColorPicker/Pages/SettingsPage.xaml.cs index a34e592c..509440e3 100644 --- a/ColorPicker/Pages/SettingsPage.xaml.cs +++ b/ColorPicker/Pages/SettingsPage.xaml.cs @@ -200,7 +200,7 @@ private void LightBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath); XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath); - Global.ChangeTheme(); + Global.ChangeTheme(true); } private void DarkBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) @@ -214,7 +214,7 @@ private void DarkBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath); XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath); - Global.ChangeTheme(); + Global.ChangeTheme(true); } private void SystemBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { @@ -227,7 +227,7 @@ private void SystemBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs SynethiaManager.Save(Global.SynethiaConfig, Global.SynethiaPath); XmlSerializerManager.SaveToXml(Global.Bookmarks, Global.BookmarksPath); - Global.ChangeTheme(); + Global.ChangeTheme(true); } private void LangComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)