关于 Xamarin Forms App.Shell 中的颜色配置,我缺少什么?

What am I missing about my color configurations in my Xamarin Forms App.Shell?

今天早些时候,我在这里寻求帮助,因为我的 Xamarin 应用程序没有像我预期的那样工作。 在获得有关如何更改操作栏颜色的帮助后,我开始想知道“为什么它在我发现的教程中所说的方式不起作用”

编辑

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:local="clr-namespace:Mobile.XamarinApp.Views"
   xmlns:sys="clr-namespace:System;assembly=netstandard"
   x:Class="Mobile.XamarinApp.AppShell"
   BackgroundColor="{StaticResource Primary}"
   Shell.ForegroundColor="{StaticResource Background}"
   Shell.TitleColor="{StaticResource Background}">
<!--
    The overall app visual hierarchy is defined here, along with navigation.
    https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/
-->
<Shell.Resources>
    <ResourceDictionary>
        <Style x:Key="BaseStyle" TargetType="Element" ApplyToDerivedTypes="True">
            <Setter Property="Shell.Title" Value="App" />
            <Setter Property="Shell.BackgroundColor" Value="{StaticResource Background}" />
            <Setter Property="Shell.ForegroundColor" Value="{StaticResource Primary}" />
            <Setter Property="Shell.TitleColor" Value="{StaticResource Primary}" />
            <Setter Property="Shell.DisabledColor" Value="HotPink" />
            <Setter Property="Shell.UnselectedColor" Value="{StaticResource Secondary}" />
            <Setter Property="Shell.TabBarBackgroundColor" Value="Red" />
            <Setter Property="Shell.TabBarForegroundColor" Value="Blue"/>
            <Setter Property="Shell.TabBarUnselectedColor" Value="Green"/>
            <Setter Property="Shell.TabBarTitleColor" Value="Yellow"/>
            <Setter Property="Shell.FlyoutHeight" Value="400"/>
            <Setter Property="Shell.FlyoutWidth" Value="200"/>
        </Style>
        
        <Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
        <Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
    
        <!--
        Default Styles for all Flyout Items
        https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyoutitem-and-menuitem-style-classes
        -->
        <Style Class="teste" TargetType="TabbedPage">
            <Setter Property="BackgroundColor" Value="Red"/>
        </Style>
        <Style Class="FlyoutItemLabelStyle" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource Accent}"></Setter>
        </Style>
        <Style Class="FlyoutItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
            <Setter Property="BackgroundColor" Value="{StaticResource Primary}"></Setter>
            <Setter Property="HeightRequest" Value="50" />
            <Setter Property="HorizontalOptions" Value="Start"/>
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="{StaticResource Secondary}" />
                                <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="White" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
        <!--
        Custom Style you can apply to any Menu Item
        -->
        <Style Class="MenuItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal">
                            <VisualState.Setters>
                                <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Accent}" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ResourceDictionary>
</Shell.Resources>

<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <Grid BackgroundColor="{StaticResource Secondary}" HeightRequest="56" Padding="10,0,10,0">
            <Label Text="Menu"
               TextColor="{StaticResource Primary}"
               FontAttributes="Bold"
               VerticalTextAlignment="Center"
                   HorizontalTextAlignment="Start"/>
        </Grid>
    </DataTemplate>
</Shell.FlyoutHeaderTemplate>

<Shell.FlyoutFooterTemplate>
    <DataTemplate>
        <StackLayout>
            <Label Text="Xaminals"
               TextColor="Black"
               FontAttributes="Bold"
               HorizontalOptions="Center" />
            <Label Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:MMMM dd, yyyy}'}"
               TextColor="Black"
               HorizontalOptions="Center" />
        </StackLayout>
    </DataTemplate>
</Shell.FlyoutFooterTemplate>

<!-- Splash Screen/Start Page -->
<!--<ShellItem Route="loading">
    <ShellContent ContentTemplate="{DataTemplate local:LoadingPage}" />
</ShellItem>-->

<!-- SignIn Page -->
<ShellContent Route="SignInPage" ContentTemplate="{DataTemplate local:SignInPage}"/>
<!-- 
    When the Flyout is visible this defines the content to display in the flyout.
    FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element    
    https://docs.microsoft.com/dotnet/api/xamarin.forms.shellgroupitem.flyoutdisplayoptions?view=xamarin-forms
-->
<FlyoutItem Title="Browse">
    <ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
</FlyoutItem>
<FlyoutItem Title="About">
    <ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
</FlyoutItem>
<FlyoutItem Title="Cadastro">
    <ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
</FlyoutItem>

<!-- When the Flyout is visible this will be a menu item you can tie a click behavior to  -->
<MenuItem Text="Sair" StyleClass="MenuItemLayoutStyle" Clicked="OnSignOutMenuItemClicked">
</MenuItem>

<!--
    TabBar lets you define content that won't show up in a flyout menu. When this content is active
    the flyout menu won't be available. This is useful for creating areas of the application where 
    you don't want users to be able to navigate away from. If you would like to navigate to this 
    content you can do so by calling 
    await Shell.Current.GoToAsync("//LoginPage");
-->

<!-- Optional Templates 
// These may be provided inline as below or as separate classes.

// This header appears at the top of the Flyout.
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyout-header
<Shell.FlyoutHeaderTemplate>
    <DataTemplate>
        <Grid>ContentHere</Grid>
    </DataTemplate>
</Shell.FlyoutHeaderTemplate>

// ItemTemplate is for ShellItems as displayed in a Flyout
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-flyoutitem-appearance
-->
<!--<Shell.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0"
                   Text="{Binding Title}"
                   FontAttributes="Italic"
                   VerticalTextAlignment="Center" />
        </Grid>
    </DataTemplate>
</Shell.ItemTemplate>-->
<!--
// MenuItemTemplate is for MenuItems as displayed in a Flyout
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-menuitem-appearance
-->
<!--<Shell.MenuItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0"
                   Text="{Binding Text}"
                   FontAttributes="Italic"
                   VerticalTextAlignment="Center" />
        </Grid>
    </DataTemplate>
</Shell.MenuItemTemplate>-->

虽然我在这3行支持Shell的配置,但它不起作用。

<Setter Property="Shell.BackgroundColor" Value="{StaticResource Background}" />
        <Setter Property="Shell.ForegroundColor" Value="{StaticResource Primary}" />
        <Setter Property="Shell.TitleColor" Value="{StaticResource Primary}" />

在获得帮助后,header 的最后 3 行 shell 配置成功了。

   BackgroundColor="{StaticResource Primary}"
   Shell.ForegroundColor="{StaticResource Background}"
   Shell.TitleColor="{StaticResource Background}"

问题是,我是不是做错了什么?我错过了什么吗?

我只是想更改我 Tabbar 的颜色、我的 Shell.Resources 词典中的操作栏等,就像教程向我们展示的那样。

提前致谢

您可能还需要在目标 ShellContent 中键入:

<Style TargetType="ShellContent" BasedOn="{StaticResource BaseStyle}"/>