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 8675603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:59:22+00:00 2026-06-12T19:59:22+00:00

I have a WPF window that enables glass on itself during its SourceInitialized event.

  • 0

I have a WPF window that enables glass on itself during its SourceInitialized event. This works perfectly. I’ll use the simplest example possible (just one window object) to demonstrate where the issue is.

public partial class MainWindow : Window
{
    public bool lolz = false;
    public MainWindow()
    {
        InitializeComponent();
        this.SourceInitialized += (x, y) =>
            {
                AeroExtend(this);
            };
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        if (!lolz)
        {
            MainWindow mw = new MainWindow();
            mw.lolz = true;
            mw.ShowDialog();
        }
    }
}

This creates two MainWindows. When I debug this in Visual Studio everything works as expected.
Perfect!

When I run without debugging, not so much.
Not perfect...

The child window has an odd, incorrectly applied glass frame… but only when running it directly without Visual Studio debugging. Same code ran twice but with different results. It doesn’t matter when I create the second window, I’ve tied it to a button click with the same output.

Any ideas?

EDIT: Here is an excerpt of the code I’m using for AeroExtend

[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);

[DllImport("dwmapi.dll", PreserveSig = false)]
private static extern bool DwmIsCompositionEnabled();

[StructLayout(LayoutKind.Sequential)]
private class MARGINS
    {
        public MARGINS(Thickness t)
        {
            cxLeftWidth = (int)t.Left;
            cxRightWidth = (int)t.Right;
            cyTopHeight = (int)t.Top;
            cyBottomHeight = (int)t.Bottom;
        }
        public int cxLeftWidth, cxRightWidth,
            cyTopHeight, cyBottomHeight;
}

...

static public bool AeroExtend(this Window window)
{
    if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled())
    {
        IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
        HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
        mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;

        window.Background = System.Windows.Media.Brushes.Transparent;

        MARGINS margins = new MARGINS(new Thickness(-1));

        int result = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
        if (result < 0)
        {
            return false;
        }
         return true;
    }
    return false;
}
  • 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-06-12T19:59:24+00:00Added an answer on June 12, 2026 at 7:59 pm

    The problem is that you have MARGINS defined as a class. You’ll notice that if you tried using a different set of values for the margin (e.g. 10 pixels on each edge) that it will still try to fill the entire area. Also as I mentioned in my comment the other day, you will notice that you have an artifact in the lower right corner even in the original window that wasn’t shown modally. If you simply change the MARGINS from a class to a struct then the problem does not occur. e.g.

    [StructLayout(LayoutKind.Sequential)]
    private struct MARGINS
    

    Alternatively you could leave MARGINS a class but then you should change the way the DwmExtendFrameIntoClientArea is defined. e.g.

    [DllImport("dwmapi.dll")]
    private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, [MarshalAs(UnmanagedType.LPStruct)] MARGINS pMargins);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have standard WPF Window that I have extended the Aero Glass on the
I have two images on a WPF window that are on top of each
I have a RichTextBox on a WPF window that I am using kind of
At the moment I have a DocumentViewer in a WPF window that displays an
I develop on VS2010 WPF on Window 7. I have a project that does
I have a WPF Window that open a modal child window to load some
I have WPF window that uses a dockpanel and the menu control. I have
I have a WPF window that has TopMost=true . When I call another Window
I have a WPF window that goes fullscreen, and I have made every attempt
I have a WPF window that contains a DataGrid at the bottom half of

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.