1

WPF中创建圆角无工具条的Window

 2 years ago
source link: http://blog.devwiki.net/archives/create-corner-background-window-in-wpf.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WPF中创建圆角无工具条的Window

一般创建的 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>

运行效果如下:

上图即为圆角窗口, 四角黑色为截图软件导致.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK