Added support for switching to Accent background color if the user requests this via Windows theme settings
This commit is contained in:
@@ -7,6 +7,8 @@ namespace TheXamlGuy.NotificationFlyout.Shared.UI.Helpers
|
|||||||
{
|
{
|
||||||
public class SystemPersonalisationHelper : IWndProcHandler
|
public class SystemPersonalisationHelper : IWndProcHandler
|
||||||
{
|
{
|
||||||
|
private static readonly Lazy<SystemPersonalisationHelper> _current = new(() => new SystemPersonalisationHelper());
|
||||||
|
|
||||||
private readonly UISettings _settings = new();
|
private readonly UISettings _settings = new();
|
||||||
private readonly string PersonalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
private readonly string PersonalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||||
private SystemTheme _currentTheme;
|
private SystemTheme _currentTheme;
|
||||||
@@ -22,10 +24,17 @@ namespace TheXamlGuy.NotificationFlyout.Shared.UI.Helpers
|
|||||||
|
|
||||||
public event EventHandler<SystemPersonalisationChangedEventArgs> ThemeChanged;
|
public event EventHandler<SystemPersonalisationChangedEventArgs> ThemeChanged;
|
||||||
|
|
||||||
|
public static SystemPersonalisationHelper Current => _current.Value;
|
||||||
public bool IsColorPrevalence => GetIsColorPrevalence();
|
public bool IsColorPrevalence => GetIsColorPrevalence();
|
||||||
public SystemTheme Theme => GetTheme();
|
public SystemTheme Theme => GetTheme();
|
||||||
|
|
||||||
public static SystemPersonalisationHelper Create() => new();
|
public void Handle(uint message, IntPtr wParam, IntPtr lParam)
|
||||||
|
{
|
||||||
|
if (message == (int)WndProcMessages.WM_SETTINGCHANGE)
|
||||||
|
{
|
||||||
|
RaiseThemeChangedEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool GetIsColorPrevalence()
|
private bool GetIsColorPrevalence()
|
||||||
{
|
{
|
||||||
@@ -53,13 +62,5 @@ namespace TheXamlGuy.NotificationFlyout.Shared.UI.Helpers
|
|||||||
ThemeChanged?.Invoke(this, new SystemPersonalisationChangedEventArgs(theme, isColorPrevalence));
|
ThemeChanged?.Invoke(this, new SystemPersonalisationChangedEventArgs(theme, isColorPrevalence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(uint message, IntPtr wParam, IntPtr lParam)
|
|
||||||
{
|
|
||||||
if (message == (int)WndProcMessages.WM_SETTINGCHANGE)
|
|
||||||
{
|
|
||||||
RaiseThemeChangedEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+18
-2
@@ -1,9 +1,25 @@
|
|||||||
using Windows.UI.Xaml.Controls;
|
using TheXamlGuy.NotificationFlyout.Shared.UI.Helpers;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||||
{
|
{
|
||||||
public class NotificationFlyoutPresenter : ContentControl
|
public class NotificationFlyoutPresenter : ContentControl
|
||||||
{
|
{
|
||||||
public NotificationFlyoutPresenter() => DefaultStyleKey = typeof(NotificationFlyoutPresenter);
|
private SystemPersonalisationHelper _systemPersonalisationHelper;
|
||||||
|
|
||||||
|
public NotificationFlyoutPresenter()
|
||||||
|
{
|
||||||
|
DefaultStyleKey = typeof(NotificationFlyoutPresenter);
|
||||||
|
|
||||||
|
_systemPersonalisationHelper = SystemPersonalisationHelper.Current;
|
||||||
|
_systemPersonalisationHelper.ThemeChanged += OnThemeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate() => UpdateThemeVisualStates(false);
|
||||||
|
|
||||||
|
private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args) => UpdateThemeVisualStates(true);
|
||||||
|
|
||||||
|
private void UpdateThemeVisualStates(bool useTransition) => VisualStateManager.GoToState(this, _systemPersonalisationHelper.IsColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", useTransition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -145,7 +145,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
_notificationIconHelper = NotificationIconHelper.Create();
|
_notificationIconHelper = NotificationIconHelper.Create();
|
||||||
_notificationIconHelper.IconInvoked += OnIconInvoked;
|
_notificationIconHelper.IconInvoked += OnIconInvoked;
|
||||||
|
|
||||||
_systemPersonalisationHelper = SystemPersonalisationHelper.Create();
|
_systemPersonalisationHelper = SystemPersonalisationHelper.Current;
|
||||||
_systemPersonalisationHelper.ThemeChanged += OnThemeChanged;
|
_systemPersonalisationHelper.ThemeChanged += OnThemeChanged;
|
||||||
|
|
||||||
UpdateIcons();
|
UpdateIcons();
|
||||||
|
|||||||
Reference in New Issue
Block a user