I haven't worked much in dwm apis so I may be wrong but I think the default dwm rendering policy is using WindowStyle to figure out rendering. If you disable that policy, it behaves as you'd expect it to.
Add the following bit to fix your blues xD
const int DWMWA_NCRENDERING_POLICY = 2;
int DWMNCRP_DISABLED = 2;
DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, ref DWMNCRP_DISABLED, sizeof(int));
For details of this voodoo, please check the following resources:
DwmSetWindowAttribute function
DWMWINDOWATTRIBUTE enumeration
MainWindow.xaml
<Window x:Class="dwm.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"/>
MainWindow.xaml.cs
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace dwm
{
public partial class MainWindow
{
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DwmBlurbehind blurBehind);
[DllImport("dwmapi.dll", PreserveSig = true)]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var bb = new DwmBlurbehind
{
dwFlags = CoreNativeMethods.DwmBlurBehindDwFlags.DwmBbEnable,
Enabled = true
};
WindowStartupLocation = WindowStartupLocation.CenterScreen;
Background = Brushes.Transparent;
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
Focus();
var hwnd = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
DwmEnableBlurBehindWindow(hwnd, ref bb);
const int dwmwaNcrenderingPolicy = 2;
var dwmncrpDisabled = 2;
DwmSetWindowAttribute(hwnd, dwmwaNcrenderingPolicy, ref dwmncrpDisabled, sizeof(int));
}
[StructLayout(LayoutKind.Sequential)]
public struct DwmBlurbehind
{
public CoreNativeMethods.DwmBlurBehindDwFlags dwFlags;
public bool Enabled;
public IntPtr BlurRegion;
public bool TransitionOnMaximized;
}
public static class CoreNativeMethods
{
public enum DwmBlurBehindDwFlags
{
DwmBbEnable = 1,
DwmBbBlurRegion = 2,
DwmBbTransitionOnMaximized = 4
}
}
}
}
Screenshot with focus
Screenshot without focus
Test Environment
OS: Windows 8 - x64
Theme: Standard windows