Example #1
0
        private static void EnableBlur(Window window, bool isEnabled)
        {
            var versionInfo = SystemHelper.GetSystemVersionInfo();

            var accentPolicy     = new InteropValues.ACCENTPOLICY();
            var accentPolicySize = Marshal.SizeOf(accentPolicy);

            accentPolicy.AccentFlags = 2;

            if (isEnabled)
            {
                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;
                }
            }
            else
            {
                accentPolicy.AccentState = InteropValues.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND;
            }

            accentPolicy.GradientColor = ResourceHelper.GetResource <uint>(ResourceToken.BlurGradientValue);

            var accentPtr = Marshal.AllocHGlobal(accentPolicySize);

            Marshal.StructureToPtr(accentPolicy, accentPtr, false);

            var data = new InteropValues.WINCOMPATTRDATA
            {
                Attribute = InteropValues.WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY,
                DataSize  = accentPolicySize,
                Data      = accentPtr
            };

            InteropMethods.Gdip.SetWindowCompositionAttribute(window.GetHandle(), ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
Example #2
0
        internal static void EnableBlur(Window window)
        {
            var accentPolicy     = new ExternDllHelper.ACCENTPOLICY();
            var accentPolicySize = Marshal.SizeOf(accentPolicy);

            if (SystemVersionInfo >= SystemVersionInfo.Windows10_1809)
            {
                accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_ACRYLICBLURBEHIND;
            }
            else if (SystemVersionInfo >= SystemVersionInfo.Windows10)
            {
                accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_BLURBEHIND;
            }
            else
            {
                var colorValue = ResourceHelper.GetResource <uint>(ResourceToken.BlurGradientValue);
                var color      = ColorHelper.ToColor(colorValue);
                color             = Color.FromRgb(color.R, color.G, color.B);
                window.Background = new SolidColorBrush(color);
                return;
            }

            accentPolicy.AccentFlags   = 2;
            accentPolicy.GradientColor = ResourceHelper.GetResource <uint>(ResourceToken.BlurGradientValue);

            var accentPtr = Marshal.AllocHGlobal(accentPolicySize);

            Marshal.StructureToPtr(accentPolicy, accentPtr, false);

            var data = new ExternDllHelper.WINCOMPATTRDATA
            {
                Attribute = ExternDllHelper.WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY,
                DataSize  = accentPolicySize,
                Data      = accentPtr
            };

            ExternDllHelper.SetWindowCompositionAttribute(window.GetHandle(), ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
Example #3
0
        internal static void EnableBlur(Window window)
        {
            var version     = WindowHelper.GetWindowsVersion();
            var versionInfo = new SystemVersionInfo(version.Major, version.Minor, version.Build);

            if (versionInfo < SystemVersionInfo.Windows10 ||
                versionInfo >= SystemVersionInfo.Windows10_1903)
            {
                var colorValue = ResourceHelper.GetResource <uint>(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;
            accentPolicy.GradientColor = ResourceHelper.GetResource <uint>(ResourceToken.BlurGradientValue);

            var accentPtr = Marshal.AllocHGlobal(accentPolicySize);

            Marshal.StructureToPtr(accentPolicy, accentPtr, false);

            var data = new InteropValues.WINCOMPATTRDATA
            {
                Attribute = InteropValues.WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY,
                DataSize  = accentPolicySize,
                Data      = accentPtr
            };

            InteropMethods.Gdip.SetWindowCompositionAttribute(window.GetHandle(), ref data);

            Marshal.FreeHGlobal(accentPtr);
        }