Early today I've asked for help here because my Xamarin App wasn't working like I expected. After the help about how to change my Action Bar color, I start wondering "why the way it says on tutorials I've found does not work"
EDIT
<?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://learn.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://learn.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://learn.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://learn.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://learn.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://learn.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>-->
While I stand for the configuration of Shell on those 3 lines, it does not work.
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Background}" />
<Setter Property="Shell.ForegroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TitleColor" Value="{StaticResource Primary}" />
After getting help, the 3 last lines shell config at the header, made it work.
BackgroundColor="{StaticResource Primary}"
Shell.ForegroundColor="{StaticResource Background}"
Shell.TitleColor="{StaticResource Background}"
The question is, am I doing something wrong? Did I miss something?
I just want to change the color of my Tabbar
, action bar and etc from my Shell.Resources Dictionary like the tutorials shows us to do.
thanks in advance
You probably have to Target ShellContent
type also:
<Style TargetType="ShellContent" BasedOn="{StaticResource BaseStyle}"/>