【问题标题】:How to remove border of window in WPF?如何在WPF中删除窗口边框?
【发布时间】:2021-04-26 09:35:14
【问题描述】:

这是通过 WPF 模板创建项目时的默认窗口:

<Window x:Class="Chaco.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:Chaco"
        mc:Ignorable="d"
        BorderThickness="0"
        BorderBrush="Transparent"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button x:Name="ButtonMain" Content="Main" Width="100" Height="50" Background="White">
        </Button>
    </Grid>
</Window>

默认窗口有黑色边框。

如何去除?

【问题讨论】:

    标签: wpf xaml window


    【解决方案1】:

    您可以设置Window.WindowStyle="ToolWindow"。你仍然会有影子。

    <Window x:Class="Chaco.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:Chaco"
            mc:Ignorable="d"
            WindowStyle="ToolWindow"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            <Button x:Name="ButtonMain" Content="Main" Width="100" Height="50" Background="White">
            </Button>
        </Grid>
    </Window>
    

    或者你可以设置WindowChrome.WindowChrome附加属性,设置GlassFrameThickness="0"也会去掉阴影:

    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="0"/>
    </WindowChrome.WindowChrome>
    

    另一种方法是在窗口旁边设置WindowStyle="None"AllowsTransparency="True"

    【讨论】:

    • 好招!但缺点是窗口处于活动状态时,顶部仍有边框。最小化和最大化按钮也不见了
    • 我没有看到任何边框,可能是缩进,但不是边框。是的,不幸的是没有按钮。所以必须手动添加。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多