packages/Windows API Code Pack 1.1/source/WindowsAPICodePack/Shell/DesktopWindowManager/GlassWindow.cs
/// <summary>
/// Excludes a UI element from the AeroGlass frame.
/// </summary>
/// <param name="element">The element to exclude.</param>
/// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not 
/// render properly on top of an AeroGlass frame. </remarks>
Excludes a UI element from the AeroGlass frame.
Excludes a UI element from the AeroGlass frame .
public void ExcludeElementFromAeroGlass(FrameworkElement element)
        {
            if (AeroGlassCompositionEnabled && element != null)
            {
                HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                NativeRect windowRect;
                NativeRect clientRect;
                DesktopWindowManagerNativeMethods.GetWindowRect(hwndSource.Handle, out windowRect);
                DesktopWindowManagerNativeMethods.GetClientRect(hwndSource.Handle, out clientRect);
                Size nonClientSize = new Size(
                        (double)(windowRect.Right - windowRect.Left) - (double)(clientRect.Right - clientRect.Left),
                        (double)(windowRect.Bottom - windowRect.Top) - (double)(clientRect.Bottom - clientRect.Top));
                GeneralTransform transform = element.TransformToAncestor(this);
                Point topLeftFrame = transform.Transform(new Point(0, 0));
                Point bottomRightFrame = transform.Transform(new Point(
                            element.ActualWidth + nonClientSize.Width,
                            element.ActualHeight + nonClientSize.Height));
                Margins margins = new Margins();
                margins.LeftWidth = (int)topLeftFrame.X;
                margins.RightWidth = (int)(this.ActualWidth - bottomRightFrame.X);
                margins.TopHeight = (int)(topLeftFrame.Y);
                margins.BottomHeight = (int)(this.ActualHeight - bottomRightFrame.Y);
                DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(windowHandle, ref margins);
            }
        }
public void ExcludeElementFromAeroGlass ( FrameworkElement element ) { if ( AeroGlassCompositionEnabled && element != null ) { HwndSource hwndSource = PresentationSource . FromVisual ( this ) as HwndSource ; NativeRect windowRect ; NativeRect clientRect ; DesktopWindowManagerNativeMethods . GetWindowRect ( hwndSource . Handle , out windowRect ) ; DesktopWindowManagerNativeMethods . GetClientRect ( hwndSource . Handle , out clientRect ) ; Size nonClientSize = new Size ( ( double ) ( windowRect . Right - windowRect . Left ) - ( double ) ( clientRect . Right - clientRect . Left ) , ( double ) ( windowRect . Bottom - windowRect . Top ) - ( double ) ( clientRect . Bottom - clientRect . Top ) ) ; GeneralTransform transform = element . TransformToAncestor ( this ) ; Point topLeftFrame = transform . Transform ( new Point ( 0 , 0 ) ) ; Point bottomRightFrame = transform . Transform ( new Point ( element . ActualWidth + nonClientSize . Width , element . ActualHeight + nonClientSize . Height ) ) ; Margins margins = new Margins ( ) ; margins . LeftWidth = ( int ) topLeftFrame . X ; margins . RightWidth = ( int ) ( this . ActualWidth - bottomRightFrame . X ) ; margins . TopHeight = ( int ) ( topLeftFrame . Y ) ; margins . BottomHeight = ( int ) ( this . ActualHeight - bottomRightFrame . Y ) ; DesktopWindowManagerNativeMethods . DwmExtendFrameIntoClientArea ( windowHandle , ref margins ) ; } }
Excludes a UI element from the AeroGlass frame.
Excludes a UI element from the AeroGlass frame .
// calculate total size of window nonclient area // calculate size of element relative to nonclient area // Create a margin structure // Extend the Frame into client area
element
FrameworkElement
The element to exclude.
The element to exclude .
remarks
Many non-WPF rendered controls  will not
render properly on top of an AeroGlass frame.
Many non - WPF rendered controls will not render properly on top of an AeroGlass frame .