From 53c720792ac0e69d183556402988b7cbaae69a0b Mon Sep 17 00:00:00 2001 From: Mahdi Hosseini Date: Sat, 10 Apr 2021 13:30:57 +0430 Subject: [PATCH] Improve BlurWindow --- .../Controls/Window/BlurWindow.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs index 9db557f3e..a9ad2a6ef 100644 --- a/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs +++ b/src/Shared/HandyControl_Shared/Controls/Window/BlurWindow.cs @@ -1,5 +1,4 @@ -using System.Runtime.InteropServices; -using System.Windows.Media; +using System.Runtime.InteropServices; using HandyControl.Data; using HandyControl.Tools; using HandyControl.Tools.Interop; @@ -26,24 +25,28 @@ internal static void EnableBlur(Window window) { var versionInfo = GetSystemVersionInfo(); - if (versionInfo < SystemVersionInfo.Windows10 || - versionInfo >= SystemVersionInfo.Windows10_1903) - { - var colorValue = ResourceHelper.GetResource(ResourceToken.BlurGradientValue); - var color = ColorHelper.ToColor(colorValue); - color = Color.FromRgb(color.R, color.G, color.B); - window.Background = new SolidColorBrush(color); - return; - } - var accentPolicy = new InteropValues.ACCENTPOLICY(); var accentPolicySize = Marshal.SizeOf(accentPolicy); - accentPolicy.AccentState = versionInfo < SystemVersionInfo.Windows10_1809 - ? InteropValues.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND - : InteropValues.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND; - accentPolicy.AccentFlags = 2; + + if (versionInfo >= SystemVersionInfo.Windows10_1903) + { + accentPolicy.AccentState = InteropValues.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND; + } + else if (versionInfo >= SystemVersionInfo.Windows10_1809) + { + accentPolicy.AccentState = InteropValues.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND; + } + else if (versionInfo >= SystemVersionInfo.Windows10) + { + accentPolicy.AccentState = InteropValues.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND; + } + else + { + accentPolicy.AccentState = InteropValues.ACCENTSTATE.ACCENT_ENABLE_TRANSPARENTGRADIENT; + } + accentPolicy.GradientColor = ResourceHelper.GetResource(ResourceToken.BlurGradientValue); var accentPtr = Marshal.AllocHGlobal(accentPolicySize);