Extending Aero glass in ribbon window...

Jul 14, 2009 at 6:12 PM

So I have some code that I found that allows the extension of the vista glass into the client region of a window (like on internet explorer)  The code works wonderfully on regular windows but not on a ribbon window.  What changes would I need to make in order to have this same effect on the ribbon window?  Here's the code:

Public Class GlassExtension

        Private Structure MARGINS
            Public Sub New(ByVal t As Thickness)
                Left = CInt(t.Left)
                Right = CInt(t.Right)
                Top = CInt(t.Top)
                Bottom = CInt(t.Bottom)
            End Sub
            Public Left As Integer
            Public Right As Integer
            Public Top As Integer
            Public Bottom As Integer
        End Structure
        <DllImport("dwmapi.dll", PreserveSig:=False)> _
        Private Shared Sub DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef margins As MARGINS)
        End Sub
        <DllImport("dwmapi.dll", PreserveSig:=False)> _
        Private Shared Function DwmIsCompositionEnabled() As Boolean
        End Function
        Public Shared Function ExtendGlassFrame(ByVal window As Window, ByVal margin As Thickness) As Boolean
            If Not DwmIsCompositionEnabled() Then
                Return False
            End If
            Dim hwnd As IntPtr = New WindowInteropHelper(window).Handle
            If hwnd = IntPtr.Zero Then
                Throw New InvalidOperationException("The Window must be shown before extending glass.")
            End If
            ' Set the background to transparent from both the WPF and Win32 perspectives
            Dim background As New SolidColorBrush(Colors.Red)
            background.Opacity = 0.5
            window.Background = Brushes.Transparent
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent
            Dim margins As New MARGINS(margin)
            DwmExtendFrameIntoClientArea(hwnd, margins)
            Return True
        End Function
    End Class
Thanks for your help! I love the control...
Jul 14, 2009 at 7:06 PM

The ribbon window is already extending glass into its client area, that's how it works. There is no API for further extending it, and if you try, you will only mess up the effect that the window is trying to manage itself.

Jul 14, 2009 at 11:42 PM

So how would one adjust the margins to allow further extension?

Jul 14, 2009 at 11:43 PM

You can't.

Jul 15, 2009 at 12:24 AM

Could you please explain... I'm having difficulty understanding.

If the glass is already partially extended why couldn't you extend it on the other side?  It seems that there would be some sort of override (like the code shown above) that would allow some additional changes...

Coordinator
Jul 16, 2009 at 8:36 PM

We didn't expose any APIs to allow you to extend the glass further.  RibbonWindow was designed as a convenience for the 90% case of just wanting the standard glass/non-client area integration which is found in Office.  If you want to extend the glass further, that's an advanced scenario which RibbonWindow was not designed to accomodate, so you'll have to roll your own implementation.  However, this is good feedback and we will certainly take this into account as we complete V1.

Jul 16, 2009 at 9:04 PM

Thanks... yeah I've just made my own custom setup and it seems to be working fine.  Thanks for the explanation and the help.

Feb 21, 2010 at 10:08 PM

Hi,

I am trying to do the same thing but having some difficulty, could you give me some pointers on how you achieved this please?

 

Thanks

 

Feb 22, 2010 at 3:02 PM

I took the above-mentioned code and ran it on startup.  If you mess with the margins a little bit you can acheive the same effect as the ribbon window and still be able to adjust other things... but that's probably an over simplification.  Let me know if there are any specific issues.

Feb 22, 2010 at 9:53 PM

Thanks - I've got it working. I was going about it the wrong way - I was trying to change the RibbonWindow, but after reading your reply I am just using an ordinary window (with code almost the same as you have, I already had that from a WPF book) and my own ControlTemplate for the Ribbon.