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>

运行效果:

相关推荐
sukalot2 小时前
windows C#-命名实参和可选实参(上)
开发语言·c#
摩天崖FuJunWANG4 小时前
vba批量化调整word的图和图表标题
开发语言·c#·word·vba程序
WangMing_X4 小时前
C# 23种设计模式(5)命令模式(Command Pattern)
开发语言·设计模式·c#·命令模式
orangapple5 小时前
WPF 用Vlc.DotNet.Wpf实现视频播放、停止、暂停功能
wpf·音视频
ysdysyn5 小时前
wpf mvvm 数据绑定数据(按钮文字表头都可以),根据长度进行换行,并把换行的文字居中
c#·wpf·mvvm
orangapple5 小时前
WPF 使用LibVLCSharp.WPF实现视频播放、停止、暂停功能
wpf
晚安苏州5 小时前
WPF ControlTemplate 控件模板
wpf
晚安苏州5 小时前
WPF 布局控件
wpf
风烟隐7 小时前
Bootstrap Blazor中使用PuppeteerSharp对HTML截图
前端·c#·bootstrap·html·.net
吉量*7 小时前
WPF系列二:窗口模式调整
wpf