You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C# WPF中创建带圆角边框与模糊背景的窗口?

实现Windows 11风格的圆角模糊窗口(WPF)

核心问题在于你之前的方案仅在矩形窗口上叠加了圆角边框,未对窗口区域做实际裁剪。要达成类似开始菜单的效果,需从窗口样式、区域裁剪、背景模糊三个维度处理:

1. 基础窗口配置

先移除默认窗口边框,开启窗口透明,为后续圆角和模糊效果铺路:

<Window x:Class="RoundBlurMenu.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="StartMenuStyle" Height="600" Width="400"
        WindowStyle="None" AllowsTransparency="True" Background="Transparent">

2. 保留窗口交互能力

用WindowChrome实现无默认边框下的窗口拖动、缩放等基础操作:

<WindowChrome.WindowChrome>
    <WindowChrome CaptionHeight="0" GlassFrameThickness="0"
                  ResizeBorderThickness="4" />
</WindowChrome.WindowChrome>

3. 构建圆角模糊容器

通过Border作为主容器实现圆角,搭配模糊效果或亚克力材质,同时裁剪内容避免超出圆角:

<Grid>
    <!-- 圆角容器+亚克力背景(更贴近Win11效果) -->
    <Border CornerRadius="16">
        <Border.Background>
            <AcrylicBrush BackgroundSource="Backdrop" TintColor="#2D2D2D" TintOpacity="0.85" Opacity="0.9"/>
        </Border.Background>
        <!-- 内容容器,强制裁剪超出圆角的部分 -->
        <Grid ClipToBounds="True">
            <!-- 此处放置菜单内容,如列表、图标等 -->
            <TextBlock Text="Win11风格开始菜单" Foreground="White" FontSize="22" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>
    </Border>
</Grid>

若无需亚克力效果,可替换为高斯模糊:

<Border CornerRadius="16" Background="#2D2D2D">
    <Border.Effect>
        <BlurEffect Radius="18" KernelType="Gaussian" />
    </Border.Effect>
    <Grid ClipToBounds="True">
        <!-- 内容区域 -->
    </Grid>
</Border>

关键说明

  • 必须开启AllowsTransparency="True"和Background="Transparent",否则圆角外的区域会显示默认窗口背景,无法呈现真正的圆角窗口
  • ClipToBounds="True"是核心,确保子元素不会超出圆角边框范围
  • 你之前的方案未处理窗口透明和内容裁剪,导致仅视觉上有圆角,窗口实际仍为矩形,以上方案从根源解决了这个问题

内容的提问来源于stack exchange,提问作者Max Makaluk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 22:57:21