C# 使用 luna 或经典时如何删除 WPF 窗口的边框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1195554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:33:23  来源:igfitidea点击:

How can I remove the border of a WPF window when using luna or classic?

c#.netwpfwindows

提问by tom greene

When I display a WPF window with WindowStyle="None", it looks great when using areo.

当我用 显示 WPF 窗口WindowStyle="None"时,使用 areo 时看起来很棒。

However, when I use luna or classic, it displays an ugly gray border about 5 pixels wide.

但是,当我使用 luna 或 classic 时,它会显示一个大约 5 像素宽的丑陋灰色边框。

Of course, if I set ResizeMode="NoResize", this border disappears, but I would like the window to be resizable (ResizeMode="CanResize").

当然,如果我设置了ResizeMode="NoResize",这个边框就会消失,但我希望窗口可以调整大小 ( ResizeMode="CanResize")。

Other non WPF applications (live mail, ie, firefox, etc.) do not display this gray border, but are still resizable.

其他非 WPF 应用程序(实时邮件,即 firefox 等)不显示此灰色边框,但仍可调整大小。

Is there a way to remove this border while still being resizable?

有没有办法在仍可调整大小的同时删除此边框?

采纳答案by Jon Galloway

I'm using the WPF Customizable Window's Essential Window. Here's my window declaration (abbreviated):

我正在使用WPF Customizable Window 的 Essential Window。这是我的窗口声明(缩写):

    <CustomWindow:EssentialWindow 
      xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
      xmlns:CustomWindow="clr-namespace:CustomWindow;assembly=CustomWindow"
      AllowsTransparency="True" Background="Transparent" 
      ResizeMode="CanResizeWithGrip"
      WindowStyle="None"
      ShowInTaskbar="True" >

回答by John Myczek

Try setting AllowsTransparencyto True on the Window.

尝试在窗口上将AllowsTransparency设置为 True。

回答by Jonathan Alfaro

I found a better answer. No need to mess around with ResizeMode. No need for interop calls. No need to set AllowsTransparency which can have side effects.

我找到了更好的答案。无需乱用 ResizeMode。不需要互操作调用。无需设置可能有副作用的 AllowsTransparency。

<WindowChrome.WindowChrome>
 <WindowChrome CaptionHeight="0" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>

I took this answer from this thread: How to create a WPF Window without a border that can be resized via a grip only?

我从这个线程中得到了这个答案:如何创建一个没有边框的 WPF 窗口,只能通过手柄调整大小?

I repost it here for people who land here searching google.

我将它转发给在这里搜索谷歌的人。