private static void SetAccentPolicy(Window window, NativeMethods.AccentState accentState) { var windowHelper = new WindowInteropHelper(window); uint _blurOpacity = (uint)0.75; uint _blurBackgroundColor = 0x990000; var accent = new NativeMethods.AccentPolicy { AccentState = accentState, AccentFlags = GetAccentFlagsForTaskbarPosition(), GradientColor = (int)((_blurOpacity << 24) | (_blurBackgroundColor & 0xFFFFFF)) }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new NativeMethods.WindowCompositionAttribData { Attribute = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
private static void SetAccentPolicy(Window window, NativeMethods.AccentState accentState) { var windowHelper = new WindowInteropHelper(window); var accent = new NativeMethods.AccentPolicy { AccentState = accentState, AccentFlags = GetAccentFlagsForTaskbarPosition() }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new NativeMethods.WindowCompositionAttribData { Attribute = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void EnableBlur(this Window win) { var windowHelper = new WindowInteropHelper(win); var accent = new NativeMethods.AccentPolicy(); var accentStructSize = Marshal.SizeOf(accent); accent.AccentState = NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND; var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new NativeMethods.WindowCompositionAttributeData { Attribute = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }