Created
April 3, 2018 14:37
-
-
Save jmacato/45e6af945e54f4ee6bdc8087a3f25e55 to your computer and use it in GitHub Desktop.
AvaloniaUI Acrylic Window test code
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
internal enum AccentState | |
{ | |
ACCENT_DISABLED = 1, | |
ACCENT_ENABLE_GRADIENT = 0, | |
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, | |
ACCENT_ENABLE_BLURBEHIND = 3, | |
ACCENT_INVALID_STATE = 4 | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct AccentPolicy | |
{ | |
public AccentState AccentState; | |
public int AccentFlags; | |
public int GradientColor; | |
public int AnimationId; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct WindowCompositionAttributeData | |
{ | |
public WindowCompositionAttribute Attribute; | |
public IntPtr Data; | |
public int SizeOfData; | |
} | |
internal enum WindowCompositionAttribute | |
{ | |
// ... | |
WCA_ACCENT_POLICY = 19 | |
// ... | |
} | |
[DllImport("user32.dll")] | |
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); | |
internal void EnableBlur() | |
{ | |
var hndl = this.PlatformImpl.Handle.Handle; | |
var accent = new AccentPolicy(); | |
accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; | |
var accentStructSize = Marshal.SizeOf(accent); | |
var accentPtr = Marshal.AllocHGlobal(accentStructSize); | |
Marshal.StructureToPtr(accent, accentPtr, false); | |
var data = new WindowCompositionAttributeData(); | |
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; | |
data.SizeOfData = accentStructSize; | |
data.Data = accentPtr; | |
SetWindowCompositionAttribute(hndl, ref data); | |
Marshal.FreeHGlobal(accentPtr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment