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>

运行效果:

相关推荐
枯萎穿心攻击23 分钟前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
Eiceblue2 小时前
【免费.NET方案】CSV到PDF与DataTable的快速转换
开发语言·pdf·c#·.net
步、步、为营4 小时前
.net开源库SignalR
开源·.net
追逐时光者6 小时前
一款开源免费、通用的 WPF 主题控件包
后端·.net
步、步、为营7 小时前
.net开源物联网项目IoTSharp
物联网·开源·.net
百锦再9 小时前
.Net配置文件appsetting.json的几种读取方法
chrome·json·.net·依赖注入·appsetting·web.config
昏睡红猹9 小时前
C#脚本化(Roslyn):如何在运行时引入nuget包
c#
张人玉10 小时前
C# 常量与变量
java·算法·c#
就是有点傻11 小时前
在C#中,可以不实例化一个类而直接调用其静态字段
c#