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>

运行效果:

相关推荐
hez201016 小时前
Runtime Async - 步入高性能异步时代
c#·.net·.net core·clr
追逐时光者1 天前
.NET Fiddle:一个方便易用的在线.NET代码编辑工具
后端·.net
mudtools1 天前
.NET驾驭Word之力:玩转文本与格式
c#·.net
唐青枫1 天前
C#.NET 数据库开发提速秘籍:SqlSugar 实战详解
c#·.net
追逐时光者2 天前
精选 4 款基于 .NET 开源、功能强大的 Windows 系统优化工具
后端·.net
mudtools2 天前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
c#·.net
大飞pkz2 天前
【设计模式】C#反射实现抽象工厂模式
设计模式·c#·抽象工厂模式·c#反射·c#反射实现抽象工厂模式
唐青枫2 天前
从入门到进阶:C#.NET Stopwatch 计时与性能测量全攻略
c#·.net
私人珍藏库2 天前
[Windows] 微软 .Net 运行库离线安装包 | Microsoft .Net Packages AIO_v09.09.25
microsoft·.net·运行库
未来之窗软件服务3 天前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟