WPF系列一:窗口设置无边框

WindowStyle

设置:WindowStyle="None",窗口无法拖拽,但可纵向和横向拉伸

cs 复制代码
<Window x:Class="WPFDemo.MainWindow.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.MainWindow"
        mc:Ignorable="d"
        WindowStyle="None" 
        Title="MainWindow" Height="450" Width="800">
    <Grid>

    </Grid>
</Window>

运行效果:

AllowsTransparency

设置:AllowsTransparency="True",但是必须同时设置WindowStyle="None",不然会报错,也不支持拖拽和拉伸

cs 复制代码
<Window x:Class="WPFDemo.MainWindow.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.MainWindow"
        mc:Ignorable="d"
        WindowStyle="None"  AllowsTransparency="True"
        Title="MainWindow" Height="450" Width="800">
    <Grid>

    </Grid>
</Window>

运行效果:

WindowChrome(推荐使用)

设置:<WindowChrome GlassFrameThickness="0" >,不影响拖拽和拉伸

cs 复制代码
<Window x:Class="WPFDemo.MainWindow.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.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="0" >
        </WindowChrome>
    </WindowChrome.WindowChrome>
</Window>

运行效果:

相关推荐
咕白m6257 分钟前
通过 C# 快速生成二维码 (QR code)
后端·.net
xb113218 分钟前
C#委托详解
开发语言·c#
全栈小精灵3 小时前
Winform入门
开发语言·机器学习·c#
用户298698530144 小时前
C#: 如何自动化创建Word可填写表单,告别手动填写时代
后端·c#·.net
mudtools7 小时前
飞书 .NET SDK 事件处理的幂等性与去重机制
websocket·.net·飞书·webhook
为自己_带盐7 小时前
在 Blazor Server 中集成 docx-preview.js 实现高保真 Word 预览
javascript·c#·word
hixiong1238 小时前
C# OpenvinoSharp部署DDDDOCR验证码识别模型
opencv·c#·ocr·openvino
唐青枫8 小时前
C#.NET ConcurrentBag<T> 设计原理与使用场景
c#·.net
玩泥巴的17 小时前
飞书 .NET SDK 事件处理的幂等性与去重机制
c#·.net·二次开发·飞书