-
Notifications
You must be signed in to change notification settings - Fork 663
/
Copy pathTitleBarHelper.cs
51 lines (44 loc) · 1.51 KB
/
TitleBarHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Microsoft.UI;
using Microsoft.UI.Xaml;
namespace WinUIGallery.Helpers;
internal class TitleBarHelper
{
// workaround as AppWindow TitleBar doesn't update caption button colors correctly when changed while app is running
// https://task.ms/44172495
public static Windows.UI.Color ApplySystemThemeToCaptionButtons(Window window)
{
var frame = App.MainWindow.GetRootFrame() as FrameworkElement;
Windows.UI.Color color;
if (frame.ActualTheme == ElementTheme.Dark)
{
color = Colors.White;
}
else
{
color = Colors.Black;
}
SetCaptionButtonColors(window, color);
return color;
}
public static void SetCaptionButtonColors(Window window, Windows.UI.Color color)
{
var res = Application.Current.Resources;
res["WindowCaptionForeground"] = color;
window.AppWindow.TitleBar.ButtonForegroundColor = color;
}
public static void SetCaptionButtonBackgroundColors(Window window, Windows.UI.Color? color)
{
var titleBar = window.AppWindow.TitleBar;
titleBar.ButtonBackgroundColor = color;
}
public static void SetForegroundColor(Window window, Windows.UI.Color? color)
{
var titleBar = window.AppWindow.TitleBar;
titleBar.ForegroundColor = color;
}
public static void SetBackgroundColor(Window window, Windows.UI.Color? color)
{
var titleBar = window.AppWindow.TitleBar;
titleBar.BackgroundColor = color;
}
}