I am trying to create a Aero glass borderless and non-resizable WPF window using the DwmEnableBlurBehindWindow
method from the DmwAPI
. However, for some strange reason the glass color of this window appears as if the window is out of focus. As you can see in the next three images, the normal windows with borders (e.g figure 1 and 2) work just fine and react as expected (dark blue in focus, whitish when out of focus (= non active)).
The borderless window with resizing allowed, shows the same behavior:
The non-resizable borderless window however will always look as if it is out of focus (as you can see in the last figure 3) both when it is active and non-active. It always looks whitish:
This is some example code of how I set the glass style:
public MainWindow()
{
InitializeComponent();
WindowStyle = WindowStyle.None;
ResizeMode = ResizeMode.NoResize;
Height = 200;
Background = Brushes.Transparent;
Loaded += MainWindow_Loaded;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var windowInteropHelper = new WindowInteropHelper(this);
var handle = windowInteropHelper.Handle;
var mainWindowSrc = HwndSource.FromHwnd(handle);
if (mainWindowSrc != null)
if (mainWindowSrc.CompositionTarget != null)
mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
var glassParams = new DwmApi.DwmBlurbehind
{
dwFlags = DwmApi.DwmBlurbehind.DWM_BB_ENABLE,
fEnable = true,
hRegionBlur = IntPtr.Zero
};
IntPtr dis = new IntPtr(2);
DwmApi.DwmSetWindowAttribute(mainWindowSrc.Handle,
DwmApi.DwmWindowAttribute.DWMWA_LAST,
dis,
sizeof(uint));
DwmApi.DwmEnableBlurBehindWindow(
handle,
glassParams
);
}
I tried focusing the window, but that doesn't seem to affect the behavior. Any ideas or pointers on how to solve this?