tags:

views:

178

answers:

2

I'd like to create a window, using WPF, that has a thin border all the way around the form - i.e. no space for the title bar with the icon/caption and min/max/close buttons. For example, the "extra" icons form of the new Windows 7 taskbar:

Example Image

I understand this can be done by setting the WindowStyle = None property, however, I am also using the DwmExtendFrameIntoClientArea API, which requires that the Background property be transparent. If I do this neither the window nor border are drawn, and only non-transparent controls on the form are drawn.

How can I achieve the thin border, whilst maintaining an Aero Glass effect on the main body of the form?

+1  A: 

Use WindowStyle="None" on the Window. See MSDN for details.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="100" Width="100" WindowStyle="None">
     Hello World
</Window>
bitbonk
you could also add a <Border> element setting the Thickness you need
Junior Mayhé
I am using the `DwmExtendFrameIntoClientArea` API to have an Aero Glass background on the whole form - setting `WindowStyle="None"` means only non-transparent parts of the form are drawn (and no border).
Rezzie
`WindowStyle="None"` will draw a border around the window exactly like in your screenshot.
bitbonk
I only get that border when I don't set the Background colour to "Transparent" (which, as far as I can tell, is required for `DwmExtendFrameIntoClientArea` to work). If the Background colour is set to Transparent (Opacity is still 1.0) then no border is drawn.
Rezzie
A: 

What you need to do is set ResizeMode=CanResize and then do the following in the code behind:

protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr LParam, ref bool handled)
{
    switch (msg)
    {
        case WM_NCHITTEST:
                    //if the mouse pointer is not over the client area of the tab
                    //ignore it - this disables resize on the glass chrome
                    //a value of 1 is the HTCLIENT enum value for the Client Area
                    if (DefWindowProc(hwnd, WM_NCHITTEST, wParam, LParam).ToInt32() == 1)
                    {
                        handled = true;
                    }
                    break;
     }
}

[DllImport("user32.dll")]
        public static extern IntPtr DefWindowProc(IntPtr hWnd, int uMsg, IntPtr wParam,
           IntPtr lParam);
Dave Mullaney