


(byte)(opaque ? 255 : params.ColorizationColor > 24), Var params = NativeMethods.DwmGetColorizationParameters() Private static Color GetWindowColorizationColor(bool opaque) Throw new InvalidOperationException("Could not get window handle.") If ((hwnd = new WindowInteropHelper(this).Handle) = IntPtr.Zero) Private void Window_SourceInitialized(object sender, EventArgs e) We have: const int WM_DWMCOLORIZATIONCOLORCHANGED = 0x320 How do I make a WPF window movable by dragging the extended window frame?.

Taking some example code from these answers of mine: The value of WM_DWMCOLORIZATIONCOLORCHANGED is 0x320 you'll want to define that as a constant somewhere so you can use it in code.Īlso, unlike WinForms, WPF windows don't have a virtual WndProc() method to override, so you have to create and hook one in as a delegate to their associated window handles (HWNDs). You do this by hooking onto the window procedure ( WndProc()). Thankfully, Windows broadcasts the WM_DWMCOLORIZATIONCOLORCHANGED window message whenever that happens, so you simply need to listen for that message and update your colors whenever it's sent. Once you obtain the color for drawing your gradient brushes, the brushes won't update when the window color scheme changes, whether manually or automatically by Windows. As suggested in the link above, you can look in the registry for the color values as an alternative to a P/Invoke, but I haven't tested that method, and as stated these are undocumented and not guaranteed to be stable. I've tested it and it works great with Windows 8 and its automatic window colorization feature. Internal static extern void DwmGetColorizationParameters(ref DWMCOLORIZATIONPARAMS params) In my own project, I make use of a call to DwmGetColorizationParameters(): internal static class NativeMethods Although, the only undocumented features involved are for obtaining the window color scheme (or as the DWM calls it, the window colorization color), which is covered in this other question: However be warned: this encompasses quite a bit of Win32 interop (this means P/Invokes into native DLLs from managed code), and is only doable with certain undocumented APIs.
