I have a WPF application (.NET Framework 4) with a custom window border. I disabled the glass frame using the WPF Shell integration library and draw my own border. However, I want to add DropShadow around the border of the window when it is not maximized. I added the shadow as follows:
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) {
See DropShadow for a WPF Borderless Window for more details.
This solution works great when working with WindowState.Normal ! However, when I maximize the application and DWMWA_NCRENDERING_POLICY off DWMWA_NCRENDERING_POLICY , the background of the window becomes slightly transparent, and most of my controls are completely different from the one I'm used to.
In the following image, you see a maximized state, as it was originally, and with a shadow code. As you can see, it completely changes the transparency of the window with the shadow code: o 
Is there something I am missing? I read through the DWM function library but cannot find the answer ...
source share