Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:26:25+00:00 2026-05-29T04:26:25+00:00

I have a WPF application (.NET Framework 4) with a custom window-border. I’ve disabled

  • 0

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 😮
enter image description here

Is there something I’m missing? I’ve been reading through the DWM Function library but can’t find the answer…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:26:26+00:00Added an answer on May 29, 2026 at 4:26 am

    After a while I revisited the problem from a different angle and figured out a better solution:

    public class GlassWindow : Window
    {
        [SuppressUnmanagedCodeSecurity]
        internal static class DwmNativeMethods
        {
            [StructLayout(LayoutKind.Sequential)]
            internal struct DwmMargins
            {
                public int cxLeftWidth;
                public int cxRightWidth;
                public int cyTopHeight;
                public int cyBottomHeight;
    
                public DwmMargins(bool fullWindow)
                {
                    this.cxLeftWidth = this.cxRightWidth = this.cyTopHeight = this.cyBottomHeight = fullWindow ? -1 : 0;
                }
            }
    
            [DllImport("DwmApi.dll")]
            internal static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref DwmMargins m);
    
            [DllImport("DwmApi.dll")]
            internal static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
        }
    
        private IntPtr windowHandle;
    
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
    
            WindowInteropHelper interopHelper = new WindowInteropHelper(this);
            this.windowHandle = interopHelper.Handle;
    
            this.ToggleAreoGlass(this.WindowState != WindowState.Maximized);
    
            this.StateChanged += this.GlassWindowStateChanged;
        }
    
        private void ToggleAreoGlass(bool value)
        {
            // Enable NcRenderingPolicy
            int attrValue = 2;
            int result = DwmNativeMethods.DwmSetWindowAttribute(this.windowHandle, 2, ref attrValue, 4);
    
            if (result == 0)
            {
                // Extend DwmFrame
                DwmNativeMethods.DwmMargins margins = new DwmNativeMethods.DwmMargins(value);
                DwmNativeMethods.DwmExtendFrameIntoClientArea(this.windowHandle, ref margins);
            }
        }
    
        private void GlassWindowStateChanged(object sender, EventArgs e)
        {
            this.ToggleAreoGlass(this.WindowState != WindowState.Maximized);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application using Aero Glass. When using the application under a
We have an WPF Application build on .net framework 3.5. Some testers find if
I have been using an MSI to install a WPF application using the .NET
I have a WPF application that is targeting the .NET Framework 4.0 Client Profile.
I have a .Net client WPF application using System.DirectoryServices and LDAP for authentication. On
I have a lot of popups in application (.NET Framework 4, WPF) and I
I have a WPF application in which I use entity framework with mysql connector/net
I have used SQLite for my .net framework 4.0 WPF application, It works perfectly
I have a WPF Application running on .NET Framework 3.0. I have run the
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.