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>

运行效果:

相关推荐
wearegogog1231 小时前
C# .NET 文件比较工具 WinForms
开发语言·c#·.net
糖不吃2 小时前
WPF值转换器
c#
学以智用2 小时前
.NET Core Swagger 超详细讲解(从入门到企业级)
后端·.net
Popeye-lxw3 小时前
由罗技 K380 键盘 FN 键模式切换引发的血案
c#
FL16238631293 小时前
C# OpenCvSharp 基于霍夫变换直线检测的文本图像倾斜校正文本图像倾斜校
开发语言·c#
故渊at3 小时前
第二板块:Android 四大组件标准化学理 | 第十二篇:四大组件全景总结与系统服务(System Server)架构
android·架构·wpf·四大组件·system service
aini_lovee5 小时前
C# 快递单打印系统(万能套打系统)
开发语言·c#
白菜上路5 小时前
C# Serilog.AspNetCore基本使用
c#·serilog
小白不白1115 小时前
C# WinForm 与 VP 二次开发
开发语言·c#
SunnyDays10116 小时前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel