From d6ab4b36f2225738a667c24e699f5487e73f0ffc Mon Sep 17 00:00:00 2001 From: Grabacr07 Date: Mon, 14 Sep 2015 03:44:28 +0900 Subject: [PATCH] refactoring --- source/SylphyHorn/Application.xaml.cs | 2 +- source/SylphyHorn/Models/Helper.cs | 25 +++++++++++--------- source/SylphyHorn/Views/TransparentWindow.cs | 6 ++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/source/SylphyHorn/Application.xaml.cs b/source/SylphyHorn/Application.xaml.cs index 946efe9..44a7f7b 100644 --- a/source/SylphyHorn/Application.xaml.cs +++ b/source/SylphyHorn/Application.xaml.cs @@ -58,7 +58,7 @@ protected override void OnStartup(StartupEventArgs e) if (GeneralSettings.AccentColor.Value == null) { - VisualHelper.ForceChangeTheme(VisualHelper.GetWindowsAccentColor()); + VisualHelper.ForceChangeAccent(VisualHelper.GetWindowsAccentColor()); } this.ShowNotifyIcon(); diff --git a/source/SylphyHorn/Models/Helper.cs b/source/SylphyHorn/Models/Helper.cs index 137dd4d..6514c14 100644 --- a/source/SylphyHorn/Models/Helper.cs +++ b/source/SylphyHorn/Models/Helper.cs @@ -91,24 +91,27 @@ public static int GetWindowsAccentColor() return color; } - public static void ForceChangeTheme(long color) + public static void ForceChangeAccent(long color) { - ForceChangeTheme(Color.FromArgb((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color)); + ForceChangeAccent(Color.FromArgb((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color)); } - public static void ForceChangeTheme(Color color) + private static FieldInfo appAccentField; + + public static void ForceChangeAccent(Color color) { color.A = byte.MaxValue; - var appAcent = typeof(ThemeService).GetField("appAccent", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(ThemeService.Current) as ResourceDictionary; - if (appAcent != null) + var fieldInfo = appAccentField ?? (appAccentField = typeof(ThemeService).GetField("appAccent", BindingFlags.Instance | BindingFlags.NonPublic)); + var appAccent = fieldInfo?.GetValue(ThemeService.Current) as ResourceDictionary; + if (appAccent != null) { - appAcent["AccentColorKey"] = color; - appAcent["AccentBrushKey"] = new SolidColorBrush(color); - appAcent["AccentActiveColorKey"] = color; - appAcent["AccentActiveBrushKey"] = new SolidColorBrush(color); - appAcent["AccentHighlightColorKey"] = color; - appAcent["AccentHighlightBrushKey"] = new SolidColorBrush(color); + appAccent["AccentColorKey"] = color; + appAccent["AccentBrushKey"] = new SolidColorBrush(color); + appAccent["AccentActiveColorKey"] = color; + appAccent["AccentActiveBrushKey"] = new SolidColorBrush(color); + appAccent["AccentHighlightColorKey"] = color; + appAccent["AccentHighlightBrushKey"] = new SolidColorBrush(color); } } } diff --git a/source/SylphyHorn/Views/TransparentWindow.cs b/source/SylphyHorn/Views/TransparentWindow.cs index 637af09..26d969e 100644 --- a/source/SylphyHorn/Views/TransparentWindow.cs +++ b/source/SylphyHorn/Views/TransparentWindow.cs @@ -26,7 +26,7 @@ protected override IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr { if (msg == (int)WM.DWMCOLORIZATIONCOLORCHANGED) { - VisualHelper.ForceChangeTheme((long)wParam); + VisualHelper.ForceChangeAccent((long)wParam); } return base.WindowProc(hwnd, msg, wParam, lParam, ref handled); @@ -35,7 +35,7 @@ protected override IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr public class RawWindow { - protected HwndSource Source { get; private set; } + public HwndSource Source { get; private set; } public IntPtr Handle => this.Source?.Handle ?? IntPtr.Zero; @@ -44,7 +44,7 @@ public virtual void Show() this.Show(new HwndSourceParameters()); } - public void Show(HwndSourceParameters parameters) + protected void Show(HwndSourceParameters parameters) { this.Source = new HwndSource(parameters); this.Source.AddHook(this.WindowProc);