XAML 如何让默认的shell弹出图标在Android黑暗主题打开/关闭时做出React

yzuktlbb  于 2022-12-07  发布在  Shell
关注(0)|答案(1)|浏览(133)

我有一个应用程序,它使用了 shell 弹出窗口。当我添加弹出窗口时,它会自动创建一个图标,如下图所示:

然而,当我关闭android dark主题时:

弹出型按钮图标仍为白色,因此难以看到:

我正在使用AppThemeBinding根据用户选择的系统主题自动为应用程序设置主题,但如果用户从Android设置中关闭了深色主题,我不知道如何将弹出图标更改为深色。
知道怎么做吗?
AppShell.xaml目前看起来如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
    
<Shell
    x:Class="MAUIApp1.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MAUIApp1"
    FlyoutBackgroundColor="{AppThemeBinding Light=#f2f2f2, Dark=#2a2a2a}">

    <Shell.Resources>
        <ResourceDictionary>
            ...
        </ResourceDictionary>
    </Shell.Resources>

    <Shell.FlyoutHeader>
        ...
    </Shell.FlyoutHeader>

    <Shell.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </Shell.ItemTemplate>

    <FlyoutItem Title="Item1" Icon="item1.svg">
        <ShellContent ContentTemplate="{DataTemplate local:page1}" Route="page1"/>
    </FlyoutItem>

    <FlyoutItem Title="Item2" Icon="item2.svg">
        <ShellContent ContentTemplate="{DataTemplate local:page2}" Route="page2"/>
    </FlyoutItem>
    
    <FlyoutItem Title="Item3" Icon="item3.svg">
        <ShellContent ContentTemplate="{DataTemplate local:page3}" Route="page3"/>
    </FlyoutItem>

    <Shell.FlyoutFooter>
        ...
    </Shell.FlyoutFooter>
</Shell>
kpbpu008

kpbpu0081#

通常,可以覆盖“壳”的“前景”颜色来实现此目的:

<Shell
    x:Class="MAUIApp1.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MAUIApp1"
    FlyoutBackgroundColor="{AppThemeBinding Light=#f2f2f2, Dark=#2a2a2a}"
    Shell.ForegroundColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}">

或者,您可以编辑Resources\Styles\styles.xaml

<Style TargetType="Shell" ApplyToDerivedTypes="True">
    <Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource Gray950}}" />
    <!--<Setter Property="Shell.ForegroundColor" Value="{OnPlatform WinUI={StaticResource Primary}, Default={StaticResource White}}" />-->
    <Setter Property="Shell.ForegroundColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
</Style>

相关问题