一般创建的 Window 窗口默认布局如下:
<Window x:Class="WPFDemo.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:WPFDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
运行效果如下:
将window的 WindowStyle
属性设置为 None
, 则可去掉顶部的菜单条.
<Window x:Class="WPFDemo.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:WPFDemo"
mc:Ignorable="d"
WindowStyle="None"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
效果如下:
现在给 Grid
外部添加一个 Border
设置圆角和背景色, 同时设置Window的 Background="Transparent"
和 AllowsTransparency="True"
<Window x:Class="WPFDemo.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:WPFDemo"
mc:Ignorable="d"
WindowStyle="None"
Background="Transparent"
AllowsTransparency="True"
Title="MainWindow" Height="450" Width="800">
<Border CornerRadius="10" Background="Red">
<Grid>
</Grid>
</Border>
</Window>
运行效果如下:
上图即为圆角窗口, 四角黑色为截图软件导致.