I have a WPF application (.NET Framework 4) with a custom window-border. I've disabled the glass border using the WPF Shell Integration Library, and draw my own border. However I want to add a DropShadow around the border of the window when not maximized. I've added a shadow like this:
private static bool DropShadow(Window window)
{
try
{
WindowInteropHelper helper = new WindowInteropHelper(window);
int val = 2;
int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 4);
if (ret1 == 0)
{
Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 };
int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m);
return ret2 == 0;
}
else
{
return false;
}
}
catch (Exception ex)
{
// Probably dwmapi.dll not found (incompatible OS)
return false;
}
}
For more details see: DropShadow for WPF Borderless Window
This solution works fine when working with a WindowState.Normal
! However when I maximize the application and disable the DWMWA_NCRENDERING_POLICY
the background of the window becomes slightly transparent and most of my controls render totally different than I'm used to.
In the following image you see the maximized state as it was originally, and with the shadow code. As you can see it totally changes the transparency of the window with the shadow code :o
Is there something I'm missing? I've been reading through the DWM Function library but can't find the answer...