使用 MAUI 7.0,下一个代码允许更改弹出窗口背景覆盖颜色,但该代码不适用于 MAUI 8.0
<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>
<Color x:Key="SystemAltMediumColor">Transparent</Color>
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="{StaticResource SystemAltMediumColor}" />
<SolidColorBrush x:Key="ContentDialogBackgroundThemeBrush" Color="{StaticResource SystemAltMediumColor}" />
<SolidColorBrush x:Key="ContentDialogDimmingThemeBrush" Color="{StaticResource SystemAltMediumColor}" />
<StaticResource x:Key="ContentDialogBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<StaticResource x:Key="PopupLightDismissOverlayBackground" ResourceKey="SystemControlPageBackgroundMediumAltMediumBrush" />
<SolidColorBrush x:Key="SliderBorderBrush" Color="#1A73E8" />
<Style TargetType="Slider">
<Setter Property="BorderBrush" Value="{StaticResource SliderBorderBrush}"/>
</Style>
</maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>
有人知道为什么它不起作用以及如何修复它吗?
更新添加一些图片
CommunityToolkit Popup 没有 Overlay color 功能。您可以在 CommunityToolkit GitHub 页面上提出功能请求。
是的,您发布的上述代码曾经可以工作,但它不适用于具有最新 CommunityToolkit.Maui nuget 的 .NET8。
但是如果您想更改叠加颜色,这里有一个解决方法。
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
...
Color="Black"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
>
//make the size to be the full screen size
<ContentView WidthRequest="1920" HeightRequest="1080">
<VerticalStackLayout WidthRequest="300" HeightRequest="300" BackgroundColor="Green">
<Image Source="dotnet_bot.png"/>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
</toolkit:Popup>