WPF:使窗口不可调整大小,但保留框架?
我有一个没有标题栏的窗口(WindowStyle == WindowStyle.None
)。整个窗户采用了 Aero 玻璃效果。当我使窗口不可调整大小(ResizeMode == ResizeMode.NoResize
)时,玻璃效果消失,我的控件只是挂在半空中。 (本质上,窗口本身消失了,但留下了它的内容。)
有没有办法让我在不删除窗框的情况下使窗口不可调整大小?
我已阅读问题在 a 上启用 Vista 玻璃效果无边框 WPF 窗口,但这并不是我想要的——我想保留窗口边框。有关我希望窗口的外观的示例,请在启用 Aero 的情况下按 Alt+Tab。
澄清一下,当鼠标悬停在窗口边框上时,我根本不希望显示调整大小光标。这基本上就是我希望我的窗口看起来像的样子:
该解决方案不必严格是 WPF——我可以通过使用 Win32 API 来实现这一点。
I have a window that does not have a title bar (WindowStyle == WindowStyle.None
). The entire window uses the Aero glass effect. When I make the window unresizeable (ResizeMode == ResizeMode.NoResize
), the glass effect disappears and my controls just hang in midair. (Essentially, the window itself disappears but leaves its contents.)
Is there a way for me to make the window unresizeable without getting rid of the window frame?
I have read the question Enable Vista glass effect on a borderless WPF window, but that's not quite what I want--I would like to keep the window border. For an example of what I would like my window to look like, hit Alt+Tab with Aero enabled.
To clarify, I do no want the resize cursors to show up at all when hovering over the window border. This is essentially what I want my window to look like:
The solution doesn't have to be strictly WPF--I am fine with hacking around with the Win32 API in order to achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以挂钩 wndproc 并拦截 WM_WINDOWPOSCHANGING信息。严格来说不是 WPF,但可能是您最好的选择。
如果您想隐藏调整大小光标,那么最好的选择是拦截 WM_NCHITTEST。调用DefWindowProc(获取默认行为),并测试返回值;如果是HTBOTTOM、HTBOTTOMLEFT、HTBOTTOMRIGHT、HTTOP、HTTOPLEFT或HTTOPRIGHT,则将返回值更改为HTBORDER。
You can hook the wndproc and intercept the WM_WINDOWPOSCHANGING message. Not strictly WPF, but probably your best bet.
If you want to hide the resize cursors, then your best bet is to intercept WM_NCHITTEST. Call the DefWindowProc (to get the default behavior), and test the return value; if it's HTBOTTOM, HTBOTTOMLEFT, HTBOTTOMRIGHT, HTTOP, HTTOPLEFT, or HTTOPRIGHT, change the return value to HTBORDER.
基于埃里克的回答。
Based on Erics answer.
一种黑客方法是设置 MinWidth/MaxWidth 和 MinHeight/MaxHeight 属性以有效地使其不可调整大小。当然,问题是您仍然会在边框上看到调整大小光标。
One hackish way to do it would be to set the MinWidth/MaxWidth and MinHeight/MaxHeight properties to effectively make it unresizeable. Of course, the problem there is you'll still get the resize cursors over the borders.
为什么不直接为窗口创建这个窗口边框呢?
它使用偏移量来设置窗口的颜色。
因此,一个简单的方法就是在窗口周围包裹整个边框,然后在其上获得自己的颜色!
Why don't you just create this window border for the window?
It's using an offset to set the colors of the window.
So, an easy way is just to wrap a whole border around your window and on top of that you get your own colors!