WPF在WindowStyle=None时去掉顶部白条

AllowsTransparency=true的办法也可以,但有一定限制。


下面这是另一种办法,借助WindowChrome:


ResizeBorderThickness属性指定的用户可以单击并拖动以调整窗口的大小的应用程序窗口外部不可见边框。

CaptionHeight属性指定不可见区域,使系统行为通常与标题栏的窗口的顶部。 这些行为包括: 单击并拖动鼠标来移动窗口,双击以最大化窗口,然后右键单击以显示系统菜单。

<Window x:Class="XXX.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XXX“
mc:Ignorable="d"
WindowChrome.WindowChrome="{DynamicResource WindowChromeKey}"
>
<Window.Resources>
<WindowChrome x:Key="WindowChromeKey">
<WindowChrome.ResizeBorderThickness>
<Thickness>5</Thickness>
</WindowChrome.ResizeBorderThickness>
<WindowChrome.CaptionHeight>0</WindowChrome.CaptionHeight>
</WindowChrome>
</Window.Resources>
<Grid>
</Grid>
</Window>

  

原文地址:https://www.cnblogs.com/zhaiganggang/p/15349805.html