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

MAUI 8如何修改Popup背景遮罩颜色?原MAUI7代码失效求解决

MAUI 8.0 中修改 Popup 背景遮罩颜色失效的原因及修复方法

失效原因

MAUI 8.0 对 WinUI 层的 Popup 实现逻辑做了调整:一方面升级了依赖的 WinUI 3 版本,另一方面修改了 Popup 遮罩层绑定的系统资源键。原来在 MAUI 7.0 中生效的PopupLightDismissOverlayBackground等资源键,不再被 MAUI 的 Popup 控件直接引用,导致旧的资源覆盖方式失效。

修复方法

在 WinUI 项目的App.xaml中,替换为 MAUI 8.0 中 Popup 遮罩实际使用的资源键即可,具体修改如下:

<maui:MauiWinUIApplication
    x:Class="TestMaui8.WinUI.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:maui="using:Microsoft.Maui"
    xmlns:local="using:TestMaui8.WinUI">
    <maui:MauiWinUIApplication.Resources>
        <!-- 定义MAUI 8.0 Popup遮罩使用的画笔资源 -->
        <SolidColorBrush x:Key="PopupLightDismissOverlayBackgroundBrush" Color="Transparent" />

        <SolidColorBrush x:Key="SliderBorderBrush" Color="#1A73E8" />
        <Style TargetType="Slider">
            <Setter Property="BorderBrush" Value="{StaticResource SliderBorderBrush}"/>
        </Style>
    </maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>

若需要自定义遮罩颜色,直接修改Color属性值即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 17:20:05