A way is to do it in XAML. For example :
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
ResizeBorderThickness="3" />
</WindowChrome.WindowChrome>
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
VS2022 .NET 6.0
I want a window without caption bar and border, but keep resizeable, I can do this by setting
AllowTransparency=True
WindowStyle=None
plus handle WM_HITTEST message and return HTLEFT, HTRIGHT, HTBOTTOMRIGHT... properly, it can restore the resize function
it look like:
The problem is, AllowTranparency will casuse performance issue, I don't want to use it. I read some Window API documentation, I try this:
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(Window.GetWindow(this)).Handle;
//Install PInvoke.User32 nuget package
_ = SetWindowLong(hwnd, WindowLongIndexFlags.GWL_STYLE, (SetWindowLongFlags)(GetWindowLong(hwnd, WindowLongIndexFlags.GWL_STYLE) & ~(int)SetWindowLongFlags.WS_CAPTION));
}
And I got this:
The window is still bordered and mini caption bar on top, so I try again:
_ = SetWindowLong(hwnd, WindowLongIndexFlags.GWL_STYLE, (SetWindowLongFlags)(GetWindowLong(hwnd, WindowLongIndexFlags.GWL_STYLE) & ~(int)SetWindowLongFlags.WS_CAPTION & ~(int)SetWindowLongFlags.WS_SIZEBOX));
I remove the "WS_SIZEBOX" style, and I got what I want except that the window can not resize, even I handle WM_HITTEST message So, how to achieve same effect as AlllowTransparency but without using AlllowTransparency?
A way is to do it in XAML. For example :
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
ResizeBorderThickness="3" />
</WindowChrome.WindowChrome>