在WPF中,经常需要对窗口进行设置,下面讲讲常用的几个设置。

窗口样式

1、无边框窗口

无边框透明窗体 设置

WindowStyle="None"--无边框,如果需要其它按钮,如缩小、放大、收缩、关闭按钮,可以自定义

AllowsTransparency="True"--只有设置了AllowsTransparency,才有1、窗体真正的隐藏边框2、背景透明有效

Background="Transparent"

窗口阴影设置

可以用Border的CornerRadius设置窗口四周圆角

设置窗口阴影--值得一提的是,如果直接用Window.Effect,效果会影响CornerRadius设置的圆角效果。

<Window.Effect>
<DropShadowEffect BlurRadius="30" Color="Gray" ShadowDepth="0" RenderingBias="Quality" ></DropShadowEffect>
</Window.Effect>

举例:

<Window x:Class="WpfApplication4.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"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen" 
        AllowsTransparency="True" WindowStyle="None" Background="Transparent">
    <Grid>
        <Border CornerRadius="5" Background="Red"></Border>
    </Grid>
</Window>
View Code

相关文章: