Skip to content

Commit

Permalink
Force titlebar repaint when selecting theme or on Windows app theme c…
Browse files Browse the repository at this point in the history
…hange
  • Loading branch information
ScrubN committed May 23, 2024
1 parent fe4d69d commit d9bd23f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions TwitchDownloaderWPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions TwitchDownloaderWPF/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/WindowSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void ComboTheme_OnSelectionChanged(object sender, SelectionChangedEventA
{
_refreshThemeOnCancel = true;
Settings.Default.GuiTheme = (string)ComboTheme.SelectedItem;
App.RequestAppThemeChange();
App.RequestAppThemeChange(true);
}
}

Expand Down

0 comments on commit d9bd23f

Please sign in to comment.