From b6d338c338a87b05eaa452783a7a5b305ce98f0a Mon Sep 17 00:00:00 2001
From: krlvm <51774833+krlvm@users.noreply.github.com>
Date: Tue, 12 Oct 2021 16:17:29 +0300
Subject: [PATCH 1/3] Reduce the frequency of AccentColor change event
---
FluentWPF/Resources/AccentColors.cs | 45 +++++++++++++++--------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/FluentWPF/Resources/AccentColors.cs b/FluentWPF/Resources/AccentColors.cs
index 722193c..1573a0b 100644
--- a/FluentWPF/Resources/AccentColors.cs
+++ b/FluentWPF/Resources/AccentColors.cs
@@ -41,6 +41,7 @@ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP
if (msg == WM_DWMCOLORIZATIONCOLORCHANGED)
{
// 再取得
+ //Console.WriteLine("WM_DWMCOLORIZATIONCOLORCHANGED");
Initialize();
}
@@ -164,34 +165,36 @@ internal static void Initialize()
// 各種Color定義
if (!SystemInfo.IsWin7())
{
- ImmersiveSystemAccent = GetColorByTypeName("ImmersiveSystemAccent");
- ImmersiveSystemAccentDark1 = GetColorByTypeName("ImmersiveSystemAccentDark1");
- ImmersiveSystemAccentDark2 = GetColorByTypeName("ImmersiveSystemAccentDark2");
- ImmersiveSystemAccentDark3 = GetColorByTypeName("ImmersiveSystemAccentDark3");
- ImmersiveSystemAccentLight1 = GetColorByTypeName("ImmersiveSystemAccentLight1");
- ImmersiveSystemAccentLight2 = GetColorByTypeName("ImmersiveSystemAccentLight2");
- ImmersiveSystemAccentLight3 = GetColorByTypeName("ImmersiveSystemAccentLight3");
+ immersiveSystemAccent = GetColorByTypeName("ImmersiveSystemAccent");
+ immersiveSystemAccentDark1 = GetColorByTypeName("ImmersiveSystemAccentDark1");
+ immersiveSystemAccentDark2 = GetColorByTypeName("ImmersiveSystemAccentDark2");
+ immersiveSystemAccentDark3 = GetColorByTypeName("ImmersiveSystemAccentDark3");
+ immersiveSystemAccentLight1 = GetColorByTypeName("ImmersiveSystemAccentLight1");
+ immersiveSystemAccentLight2 = GetColorByTypeName("ImmersiveSystemAccentLight2");
+ immersiveSystemAccentLight3 = GetColorByTypeName("ImmersiveSystemAccentLight3");
}
else
{
// Windows7の場合は、OSにテーマカラーの設定はないので、固定値を使用する。
- ImmersiveSystemAccent = (Color)ColorConverter.ConvertFromString("#FF2990CC");
- ImmersiveSystemAccentDark1 = (Color)ColorConverter.ConvertFromString("#FF2481B6");
- ImmersiveSystemAccentDark2 = (Color)ColorConverter.ConvertFromString("#FF2071A1");
- ImmersiveSystemAccentDark3 = (Color)ColorConverter.ConvertFromString("#FF205B7E");
- ImmersiveSystemAccentLight1 = (Color)ColorConverter.ConvertFromString("#FF2D9FE1");
- ImmersiveSystemAccentLight2 = (Color)ColorConverter.ConvertFromString("#FF51A5D6");
- ImmersiveSystemAccentLight3 = (Color)ColorConverter.ConvertFromString("#FF7BB1D0");
+ immersiveSystemAccent = (Color)ColorConverter.ConvertFromString("#FF2990CC");
+ immersiveSystemAccentDark1 = (Color)ColorConverter.ConvertFromString("#FF2481B6");
+ immersiveSystemAccentDark2 = (Color)ColorConverter.ConvertFromString("#FF2071A1");
+ immersiveSystemAccentDark3 = (Color)ColorConverter.ConvertFromString("#FF205B7E");
+ immersiveSystemAccentLight1 = (Color)ColorConverter.ConvertFromString("#FF2D9FE1");
+ immersiveSystemAccentLight2 = (Color)ColorConverter.ConvertFromString("#FF51A5D6");
+ immersiveSystemAccentLight3 = (Color)ColorConverter.ConvertFromString("#FF7BB1D0");
}
// ブラシ類の定義
- ImmersiveSystemAccentBrush = CreateBrush(ImmersiveSystemAccent);
- ImmersiveSystemAccentDark1Brush = CreateBrush(ImmersiveSystemAccentDark1);
- ImmersiveSystemAccentDark2Brush = CreateBrush(ImmersiveSystemAccentDark2);
- ImmersiveSystemAccentDark3Brush = CreateBrush(ImmersiveSystemAccentDark3);
- ImmersiveSystemAccentLight1Brush = CreateBrush(ImmersiveSystemAccentLight1);
- ImmersiveSystemAccentLight2Brush = CreateBrush(ImmersiveSystemAccentLight2);
- ImmersiveSystemAccentLight3Brush = CreateBrush(ImmersiveSystemAccentLight3);
+ immersiveSystemAccentBrush = CreateBrush(ImmersiveSystemAccent);
+ immersiveSystemAccentDark1Brush = CreateBrush(ImmersiveSystemAccentDark1);
+ immersiveSystemAccentDark2Brush = CreateBrush(ImmersiveSystemAccentDark2);
+ immersiveSystemAccentDark3Brush = CreateBrush(ImmersiveSystemAccentDark3);
+ immersiveSystemAccentLight1Brush = CreateBrush(ImmersiveSystemAccentLight1);
+ immersiveSystemAccentLight2Brush = CreateBrush(ImmersiveSystemAccentLight2);
+ immersiveSystemAccentLight3Brush = CreateBrush(ImmersiveSystemAccentLight3);
+
+ OnStaticPropertyChanged();
}
internal static Brush CreateBrush(Color color)
From e916515f3b5d23488057138baa6c8967ab5adf84 Mon Sep 17 00:00:00 2001
From: krlvm <51774833+krlvm@users.noreply.github.com>
Date: Tue, 12 Oct 2021 22:16:19 +0300
Subject: [PATCH 2/3] Use Windows.UI.Composition.UISettings to determine Accent
Color on Windows 10
Co-Authored-By: Selastin <72641365+Extrimis@users.noreply.github.com>
---
FluentWPF/FluentWPF.csproj | 24 +++++++
FluentWPF/Properties/Settings.Designer.cs | 10 +--
FluentWPF/Resources/AccentColors.cs | 85 ++++++++++++++---------
3 files changed, 82 insertions(+), 37 deletions(-)
diff --git a/FluentWPF/FluentWPF.csproj b/FluentWPF/FluentWPF.csproj
index 8c4d418..ea9ef67 100644
--- a/FluentWPF/FluentWPF.csproj
+++ b/FluentWPF/FluentWPF.csproj
@@ -52,6 +52,15 @@
+
+
+ ..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
+
+
+ C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
+ true
+
+
@@ -59,4 +68,19 @@
+
+
+ True
+ True
+ Settings.settings
+
+
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
\ No newline at end of file
diff --git a/FluentWPF/Properties/Settings.Designer.cs b/FluentWPF/Properties/Settings.Designer.cs
index 99f0685..70a26df 100644
--- a/FluentWPF/Properties/Settings.Designer.cs
+++ b/FluentWPF/Properties/Settings.Designer.cs
@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
//
-// このコードはツールによって生成されました。
-// ランタイム バージョン:4.0.30319.42000
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
//
-// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
-// コードが再生成されるときに損失したりします。
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
//
//------------------------------------------------------------------------------
@@ -12,7 +12,7 @@ namespace SourceChord.FluentWPF.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.1.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
diff --git a/FluentWPF/Resources/AccentColors.cs b/FluentWPF/Resources/AccentColors.cs
index 1573a0b..b0ab6d0 100644
--- a/FluentWPF/Resources/AccentColors.cs
+++ b/FluentWPF/Resources/AccentColors.cs
@@ -1,13 +1,11 @@
using SourceChord.FluentWPF.Utility;
using System;
-using System.Collections.Generic;
using System.ComponentModel;
-using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Media;
+using System.Windows.Threading;
+using Windows.UI.ViewManagement;
namespace SourceChord.FluentWPF
{
@@ -22,12 +20,16 @@ public class AccentColors : ThemeHandler
private static readonly int WM_DWMCOLORIZATIONCOLORCHANGED = 0x0320;
-
+ private static readonly UISettings settings = new UISettings();
static AccentColors()
{
AccentColors.Instance = new AccentColors();
+ if (SystemInfo.IsWin10())
+ {
+ settings.ColorValuesChanged += OnWin10AccentColorChanged;
+ }
Initialize();
}
@@ -36,9 +38,17 @@ public AccentColors()
}
+ private static void OnWin10AccentColorChanged(UISettings sender, object args)
+ {
+ Dispatcher.CurrentDispatcher.Invoke(() =>
+ {
+ Initialize();
+ });
+ }
+
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
- if (msg == WM_DWMCOLORIZATIONCOLORCHANGED)
+ if (!SystemInfo.IsWin10() && msg == WM_DWMCOLORIZATIONCOLORCHANGED)
{
// 再取得
//Console.WriteLine("WM_DWMCOLORIZATIONCOLORCHANGED");
@@ -158,43 +168,54 @@ public static Brush ImmersiveSystemAccentLight3Brush
}
#endregion
-
-
internal static void Initialize()
{
// 各種Color定義
- if (!SystemInfo.IsWin7())
+ if (SystemInfo.IsWin10())
{
- immersiveSystemAccent = GetColorByTypeName("ImmersiveSystemAccent");
- immersiveSystemAccentDark1 = GetColorByTypeName("ImmersiveSystemAccentDark1");
- immersiveSystemAccentDark2 = GetColorByTypeName("ImmersiveSystemAccentDark2");
- immersiveSystemAccentDark3 = GetColorByTypeName("ImmersiveSystemAccentDark3");
- immersiveSystemAccentLight1 = GetColorByTypeName("ImmersiveSystemAccentLight1");
- immersiveSystemAccentLight2 = GetColorByTypeName("ImmersiveSystemAccentLight2");
- immersiveSystemAccentLight3 = GetColorByTypeName("ImmersiveSystemAccentLight3");
+ ImmersiveSystemAccent = TranslateColor(settings.GetColorValue(UIColorType.Accent));
+ ImmersiveSystemAccentDark1 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark1));
+ ImmersiveSystemAccentDark2 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark2));
+ ImmersiveSystemAccentDark3 = TranslateColor(settings.GetColorValue(UIColorType.AccentDark3));
+ ImmersiveSystemAccentLight1 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight1));
+ ImmersiveSystemAccentLight2 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight1));
+ ImmersiveSystemAccentLight3 = TranslateColor(settings.GetColorValue(UIColorType.AccentLight2));
+ }
+ else if (!SystemInfo.IsWin7())
+ {
+ ImmersiveSystemAccent = GetColorByTypeName("ImmersiveSystemAccent");
+ ImmersiveSystemAccentDark1 = GetColorByTypeName("ImmersiveSystemAccentDark1");
+ ImmersiveSystemAccentDark2 = GetColorByTypeName("ImmersiveSystemAccentDark2");
+ ImmersiveSystemAccentDark3 = GetColorByTypeName("ImmersiveSystemAccentDark3");
+ ImmersiveSystemAccentLight1 = GetColorByTypeName("ImmersiveSystemAccentLight1");
+ ImmersiveSystemAccentLight2 = GetColorByTypeName("ImmersiveSystemAccentLight2");
+ ImmersiveSystemAccentLight3 = GetColorByTypeName("ImmersiveSystemAccentLight3");
}
else
{
// Windows7の場合は、OSにテーマカラーの設定はないので、固定値を使用する。
- immersiveSystemAccent = (Color)ColorConverter.ConvertFromString("#FF2990CC");
- immersiveSystemAccentDark1 = (Color)ColorConverter.ConvertFromString("#FF2481B6");
- immersiveSystemAccentDark2 = (Color)ColorConverter.ConvertFromString("#FF2071A1");
- immersiveSystemAccentDark3 = (Color)ColorConverter.ConvertFromString("#FF205B7E");
- immersiveSystemAccentLight1 = (Color)ColorConverter.ConvertFromString("#FF2D9FE1");
- immersiveSystemAccentLight2 = (Color)ColorConverter.ConvertFromString("#FF51A5D6");
- immersiveSystemAccentLight3 = (Color)ColorConverter.ConvertFromString("#FF7BB1D0");
+ ImmersiveSystemAccent = (Color)ColorConverter.ConvertFromString("#FF2990CC");
+ ImmersiveSystemAccentDark1 = (Color)ColorConverter.ConvertFromString("#FF2481B6");
+ ImmersiveSystemAccentDark2 = (Color)ColorConverter.ConvertFromString("#FF2071A1");
+ ImmersiveSystemAccentDark3 = (Color)ColorConverter.ConvertFromString("#FF205B7E");
+ ImmersiveSystemAccentLight1 = (Color)ColorConverter.ConvertFromString("#FF2D9FE1");
+ ImmersiveSystemAccentLight2 = (Color)ColorConverter.ConvertFromString("#FF51A5D6");
+ ImmersiveSystemAccentLight3 = (Color)ColorConverter.ConvertFromString("#FF7BB1D0");
}
// ブラシ類の定義
- immersiveSystemAccentBrush = CreateBrush(ImmersiveSystemAccent);
- immersiveSystemAccentDark1Brush = CreateBrush(ImmersiveSystemAccentDark1);
- immersiveSystemAccentDark2Brush = CreateBrush(ImmersiveSystemAccentDark2);
- immersiveSystemAccentDark3Brush = CreateBrush(ImmersiveSystemAccentDark3);
- immersiveSystemAccentLight1Brush = CreateBrush(ImmersiveSystemAccentLight1);
- immersiveSystemAccentLight2Brush = CreateBrush(ImmersiveSystemAccentLight2);
- immersiveSystemAccentLight3Brush = CreateBrush(ImmersiveSystemAccentLight3);
+ ImmersiveSystemAccentBrush = CreateBrush(ImmersiveSystemAccent);
+ ImmersiveSystemAccentDark1Brush = CreateBrush(ImmersiveSystemAccentDark1);
+ ImmersiveSystemAccentDark2Brush = CreateBrush(ImmersiveSystemAccentDark2);
+ ImmersiveSystemAccentDark3Brush = CreateBrush(ImmersiveSystemAccentDark3);
+ ImmersiveSystemAccentLight1Brush = CreateBrush(ImmersiveSystemAccentLight1);
+ ImmersiveSystemAccentLight2Brush = CreateBrush(ImmersiveSystemAccentLight2);
+ ImmersiveSystemAccentLight3Brush = CreateBrush(ImmersiveSystemAccentLight3);
+ }
- OnStaticPropertyChanged();
+ internal static Color TranslateColor(Windows.UI.Color color)
+ {
+ return Color.FromArgb(color.A, color.R, color.G, color.B);
}
internal static Brush CreateBrush(Color color)
@@ -206,7 +227,7 @@ internal static Brush CreateBrush(Color color)
public static event EventHandler StaticPropertyChanged;
- protected static void OnStaticPropertyChanged([CallerMemberName]string propertyName = null)
+ protected static void OnStaticPropertyChanged([CallerMemberName] string propertyName = null)
{
StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
}
From 77a7878ada0afa643683605dd48852867d87588c Mon Sep 17 00:00:00 2001
From: krlvm <51774833+krlvm@users.noreply.github.com>
Date: Tue, 12 Oct 2021 22:25:23 +0300
Subject: [PATCH 3/3] Use environment variables to determine WinRT DLLs path
---
FluentWPF/FluentWPF.csproj | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/FluentWPF/FluentWPF.csproj b/FluentWPF/FluentWPF.csproj
index ea9ef67..54e3575 100644
--- a/FluentWPF/FluentWPF.csproj
+++ b/FluentWPF/FluentWPF.csproj
@@ -54,10 +54,10 @@
- ..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
+ $(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
- C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
+ $(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
true