-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThemeHelper.cs
More file actions
54 lines (46 loc) · 1.97 KB
/
ThemeHelper.cs
File metadata and controls
54 lines (46 loc) · 1.97 KB
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
52
53
54
using Microsoft.UI.Xaml;
namespace NoteUI;
/// <summary>
/// Reliable theme detection based on the root FrameworkElement's ActualTheme.
/// WinUI 3 framework brushes cannot be resolved from code-behind via
/// Application.Current.Resources when the app theme differs from the system theme.
/// Instead, rely on XAML theme inheritance (no explicit Foreground on elements)
/// and use IsDark() for any conditional styling in code-behind.
/// </summary>
internal static class ThemeHelper
{
private static FrameworkElement? _root;
/// <summary>
/// Call once after the root Content has RequestedTheme set.
/// </summary>
internal static void Initialize(FrameworkElement root)
{
_root = root;
}
/// <summary>
/// Returns true when the app is in dark mode, based on ActualTheme.
/// </summary>
internal static bool IsDark()
{
if (_root != null)
return _root.ActualTheme == ElementTheme.Dark;
// Fallback before initialization: system detection
try
{
var uiSettings = new Windows.UI.ViewManagement.UISettings();
var bg = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
return bg.R < 128;
}
catch { return false; }
}
// ── Card background colors ────────────────────────────────
// Semi-transparent overlays that work on Mica/Acrylic backdrops.
internal static Windows.UI.Color CardBackground =>
IsDark()
? Windows.UI.Color.FromArgb(0x0D, 0xFF, 0xFF, 0xFF) // subtle white overlay
: Windows.UI.Color.FromArgb(0xB3, 0xFF, 0xFF, 0xFF); // 70 % white
internal static Windows.UI.Color CardBackgroundWithColor(Windows.UI.Color noteColor) =>
IsDark()
? Windows.UI.Color.FromArgb(30, noteColor.R, noteColor.G, noteColor.B)
: CardBackground; // light mode: neutral card + color bar only
}