Created
December 24, 2015 14:19
-
-
Save lances101/28b1b67a38e948c2bee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Blur Handling | |
/* | |
Found on https://github.com/riverar/sample-win10-aeroglass | |
*/ | |
private enum AccentState | |
{ | |
ACCENT_DISABLED = 0, | |
ACCENT_ENABLE_GRADIENT = 1, | |
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, | |
ACCENT_ENABLE_BLURBEHIND = 3, | |
ACCENT_INVALID_STATE = 4 | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
private struct AccentPolicy | |
{ | |
public AccentState AccentState; | |
public int AccentFlags; | |
public int GradientColor; | |
public int AnimationId; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
private struct WindowCompositionAttributeData | |
{ | |
public WindowCompositionAttribute Attribute; | |
public IntPtr Data; | |
public int SizeOfData; | |
} | |
private enum WindowCompositionAttribute | |
{ | |
WCA_ACCENT_POLICY = 19 | |
} | |
[DllImport("user32.dll")] | |
private static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); | |
/// <summary> | |
/// Sets the blur for a window via SetWindowCompositionAttribute | |
/// </summary> | |
/// <param name="wind">window to blur</param> | |
/// <param name="isBlur">true/false - on or off correspondingly</param> | |
private void SetBlurForWindow(Window wind, bool isBlur) | |
{ | |
if (isBlur) | |
{ | |
SetWindowAccent(wind, AccentState.ACCENT_ENABLE_BLURBEHIND); | |
} | |
} | |
private void SetWindowAccent(Window wind, AccentState themeAccentMode) | |
{ | |
var windowHelper = new WindowInteropHelper(wind); | |
var accent = new AccentPolicy { AccentState = themeAccentMode }; | |
var accentStructSize = Marshal.SizeOf(accent); | |
var accentPtr = Marshal.AllocHGlobal(accentStructSize); | |
Marshal.StructureToPtr(accent, accentPtr, false); | |
var data = new WindowCompositionAttributeData | |
{ | |
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, | |
SizeOfData = accentStructSize, | |
Data = accentPtr | |
}; | |
SetWindowCompositionAttribute(windowHelper.Handle, ref data); | |
Marshal.FreeHGlobal(accentPtr); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment