Thin-border on WPF window?
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 http://img576.imageshack.us/img576/6196/border.png
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 maintainin开发者_C百科g an Aero Glass effect on the main body of the form?
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>
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);
Or use the Microsoft WPF Shell Integration Library
精彩评论