The solution to keeping the visual style of a WPF window to active even if the window loses focus is to handle the WM_NCACTIVATE
like this:
private const uint WM_NCACTIVATE = 0x0086;
private IntPtr WndProc(IntPtr hwnd, int msg,
IntPtr wParam, IntPtr lParam, ref bool handled)
{
var returnvalue = IntPtr.Zero;
if (msg == WM_NCACTIVATE)
{
//replace the wParam (true/false) which indicates
//active/inactive with always true
returnvalue = DefWindowProc(hwnd, WM_NCACTIVATE,
new IntPtr(1), new IntPtr(-1));
handled = true;
}
}
[DllImport("user32.dll")]
static extern IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages uMsg, IntPtr wParam, IntPtr lParam);