如您所知,当allow transparent属性为true时,窗口的边框将被隐藏,我们无法重新调整窗口大小。如果我们将ResizeMode设置为CanResizeWithGrip,我们只会重新调整窗口的大小,但解决方案并不好,因为我们可以在窗口最大化时重新调整窗口大小,并在窗口的右角而不是所有4个角落进行更改,因此问题是如何在不使用CanResizeWithGrip的情况下如何在允许透明为真的情况下重新调整WPF中的窗口大小?
提前致谢!
〜氏
答案 0 :(得分:5)
我的预期是设置窗口可以用隐藏边框重新调整大小,所以最后我找到了一个解决方案来处理它,你可以按照下面的代码:
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="1"
CornerRadius ="0"
ResizeBorderThickness="4"
GlassFrameThickness="0">
</WindowChrome>
</WindowChrome.WindowChrome>
如果您想了解更多信息,请添加更多讨论。
答案 1 :(得分:1)
嗯,这实际上非常简单。窗口上有一个名为ResizeMode的属性,如果将其设置为“CanResizeWithGrip”,则会自动在窗口上放置一个ResizeGrip控件,如果运行该应用程序,它将正确调整窗口大小
答案 2 :(得分:1)
有一个类似的问题 我认为它也适合你的情况。
How to create a WPF Window without a border that can be resized via a grip only?
总结一下,
添加隐藏的夹点,可以是主窗口的矩形或边框
将下面的方法附加到握把的事件上。
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
//Attach this to the MouseDown event of your drag control to move the window in place of the title bar
private void WindowDrag(object sender, MouseButtonEventArgs e) // MouseDown
{
ReleaseCapture();
SendMessage(new WindowInteropHelper(this).Handle,
0xA1, (IntPtr)0x2, (IntPtr)0);
}
//Attach this to the PreviewMousLeftButtonDown event of the grip control in the lower right corner of the form to resize the window
private void WindowResize(object sender, MouseButtonEventArgs e) //PreviewMousLeftButtonDown
{
HwndSource hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
SendMessage(hwndSource.Handle, 0x112, (IntPtr)61448, IntPtr.Zero);
}
但是,如果将AllowTransparency设置为true,则会使默认的WPF WebBrowser不可见,也会出现其他挫折。
在上面的链接中有很好的解释。