wpf 如何使用WindowStyle = None删除WPF窗口顶部的白色条带?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36631165/
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
How to remove white strip on top of WPF window with WindowStyle=None?
提问by Joginder S Nahil
回答by Carbine
What you are seeing in white is the re-size border. You can remove that and still make the window resizable by setting ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
您在白色中看到的是重新调整大小的边框。您可以删除它并仍然通过设置使窗口可调整大小ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
If you dont want to resize at all then do this - ResizeMode="NoResize", again you wont see the border but you cant resize.
如果您根本不想调整大小,请执行此操作 - ResizeMode="NoResize",您将再次看不到边框但无法调整大小。
<Window x:Class="HandsOnSolution.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="Green" WindowStyle="None" ResizeMode="CanResizeWithGrip" AllowsTransparency="True">
<Grid>
</Grid>
</Window>
Edit
编辑
Good point by @devuxer, if you are interested in dragging you can add this piece of code to the window mouse down event
@devuxer 的好点子,如果您对拖动感兴趣,可以将这段代码添加到窗口鼠标按下事件中
<Window MouseLeftButtonDown="Window_MouseLeftButtonDown"/>
//code behind
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
回答by Yashash Gaurav
I had been hunting for a solution for a couple of days now, in simple words thislink held the answer to my queries
几天来我一直在寻找解决方案,简单地说,这个链接包含了我的疑问的答案
though the code snippet that did the magic was:
尽管发挥魔力的代码片段是:
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="0"
CornerRadius="2"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="3"/>
</Setter.Value>
</Setter>
I just added the above property setter to the custom Window Style.
我刚刚将上述属性设置器添加到自定义窗口样式中。
Hope that helped :)
希望有所帮助:)
回答by Mateusz Piwowarski
I added this piece of code:
我添加了这段代码:
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0,0,0,1" CornerRadius="0" />
</WindowChrome.WindowChrome>
inside <Window> paste here <Window/>and it helped :)
在里面<Window> paste here <Window/>,它有帮助:)
回答by Yasser Elarabi
A much simplified code, acting on only one property:
一个非常简化的代码,仅作用于一个属性:
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0"/>
</WindowChrome.WindowChrome>


