diff --git a/TwitchDownloaderWPF/App.xaml b/TwitchDownloaderWPF/App.xaml index 6c6c13e5..0c9e5f83 100644 --- a/TwitchDownloaderWPF/App.xaml +++ b/TwitchDownloaderWPF/App.xaml @@ -41,7 +41,7 @@ - diff --git a/TwitchDownloaderWPF/App.xaml.cs b/TwitchDownloaderWPF/App.xaml.cs index e9b6af74..74000a23 100644 --- a/TwitchDownloaderWPF/App.xaml.cs +++ b/TwitchDownloaderWPF/App.xaml.cs @@ -54,8 +54,8 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc Current?.Shutdown(); } - public static void RequestAppThemeChange() - => ThemeServiceSingleton.ChangeAppTheme(); + public static void RequestAppThemeChange(bool forceRepaint = false) + => ThemeServiceSingleton.ChangeAppTheme(forceRepaint); public static void RequestTitleBarChange() => ThemeServiceSingleton.SetTitleBarTheme(Current.Windows); diff --git a/TwitchDownloaderWPF/MainWindow.xaml b/TwitchDownloaderWPF/MainWindow.xaml index 743f28f3..6fe620c4 100644 --- a/TwitchDownloaderWPF/MainWindow.xaml +++ b/TwitchDownloaderWPF/MainWindow.xaml @@ -9,7 +9,7 @@ lex:ResxLocalizationProvider.DefaultAssembly="TwitchDownloaderWPF" lex:ResxLocalizationProvider.DefaultDictionary="Strings" mc:Ignorable="d" - Title="Twitch Downloader" MinHeight="440" Height="500" MinWidth="700" Width="850" Loaded="Window_Loaded"> + Title="Twitch Downloader" MinHeight="440" Height="500" MinWidth="700" Width="850" Loaded="Window_Loaded" SourceInitialized="Window_OnSourceInitialized"> diff --git a/TwitchDownloaderWPF/MainWindow.xaml.cs b/TwitchDownloaderWPF/MainWindow.xaml.cs index 22d9e2a5..cd2fab8d 100644 --- a/TwitchDownloaderWPF/MainWindow.xaml.cs +++ b/TwitchDownloaderWPF/MainWindow.xaml.cs @@ -63,10 +63,13 @@ private void btnQueue_Click(object sender, RoutedEventArgs e) Main.Content = pageQueue; } - private async void Window_Loaded(object sender, RoutedEventArgs e) + private void Window_OnSourceInitialized(object sender, EventArgs e) { App.RequestAppThemeChange(); + } + private async void Window_Loaded(object sender, RoutedEventArgs e) + { Main.Content = pageVodDownload; if (Settings.Default.UpgradeRequired) { diff --git a/TwitchDownloaderWPF/Services/ThemeService.cs b/TwitchDownloaderWPF/Services/ThemeService.cs index 04f60181..513c45d7 100644 --- a/TwitchDownloaderWPF/Services/ThemeService.cs +++ b/TwitchDownloaderWPF/Services/ThemeService.cs @@ -66,11 +66,11 @@ private void WindowsThemeChanged(object sender, string newWindowsTheme) if (Settings.Default.GuiTheme.Equals("System", StringComparison.OrdinalIgnoreCase)) { - ChangeAppTheme(); + ChangeAppTheme(true); } } - public void ChangeAppTheme() + public void ChangeAppTheme(bool forceRepaint = false) { var newTheme = Settings.Default.GuiTheme; if (newTheme.Equals("System", StringComparison.OrdinalIgnoreCase)) @@ -87,6 +87,20 @@ public void ChangeAppTheme() { SetTitleBarTheme(_wpfApplication.Windows); } + + if (forceRepaint) + { + // Cause an NC repaint by changing focus + var wnd = new Window + { + SizeToContent = SizeToContent.WidthAndHeight, + Top = int.MinValue + 1, + WindowStyle = WindowStyle.None, + ShowInTaskbar = false + }; + wnd.Show(); + wnd.Close(); + } } [SupportedOSPlatform("windows")] @@ -111,19 +125,6 @@ public void SetTitleBarTheme(WindowCollection windows) _ = NativeFunctions.SetWindowAttribute(windowHandle, darkTitleBarAttribute, &shouldUseDarkTitleBar, sizeof(int)); } } - - Window wnd = new() - { - SizeToContent = SizeToContent.WidthAndHeight, - Top = int.MinValue + 1, - WindowStyle = WindowStyle.None, - ShowInTaskbar = false - }; - wnd.Show(); - wnd.Close(); - // Dark title bar is a bit buggy, requires window redraw (focus change, resize, transparency change) to fully apply. - // We *could* send a repaint message to win32.dll, but this solution works and is way easier. - // Win11 might not have this issue but Win10 does so please leave this } private void ChangeThemePath(string newTheme) diff --git a/TwitchDownloaderWPF/WindowMassDownload.xaml b/TwitchDownloaderWPF/WindowMassDownload.xaml index 53cf01f3..ba744190 100644 --- a/TwitchDownloaderWPF/WindowMassDownload.xaml +++ b/TwitchDownloaderWPF/WindowMassDownload.xaml @@ -13,7 +13,7 @@ xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf" xmlns:gif="http://wpfanimatedgif.codeplex.com" mc:Ignorable="d" - Title="Mass Downloader" MinHeight="250" Height="700" MinWidth="775" Width="1100" Loaded="Window_Loaded"> + Title="Mass Downloader" MinHeight="250" Height="700" MinWidth="775" Width="1100" Loaded="Window_Loaded" SourceInitialized="Window_OnSourceInitialized">