Skip to content

Unable to programmatically set color of Shell icon in .Net 9 when FlyoutBehavior is disabled #27000

@kevinjohnobrien

Description

@kevinjohnobrien

Description

Prior to upgrading to .Net 9, I was able to programmatically change the color of a Shell icon using the following code in AppShell.xaml.cs:

MainPage.Icon = new FontImageSource
{
    FontFamily = "FASolid",
    Glyph = "\uf130",
    Color = Colors.GreenYellow
};

When using Shell.FlyoutBehavior="Disabled" with the following code, it results in the colors not being updated, but instead uses the colors set in Styles.xaml (which I think was an issue before):

<TabBar 
    CurrentItem="{Reference MainPage}">
    <ShellContent
        Title="Main"
        x:Name="MainPage"
        ContentTemplate="{DataTemplate local:MainPage}"
        IsVisible="True">
    </ShellContent>
    <ShellContent
        Title="Main2"
        x:Name="MainPage2"
        ContentTemplate="{DataTemplate local:MainPage}"
        IsVisible="True">
    </ShellContent>
</TabBar>

However, when using Shell.FlyoutBehavior="Flyout", the colors work fine...

<ShellContent
    Title="Main"
    x:Name="MainPage"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

<ShellContent
    Title="Main2"
    x:Name="MainPage2"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

Have recreated issue in iOS simulator and MacCatalyst.

Steps to Reproduce

  1. Create a new Maui App
  2. Add the following code to AppShell.xaml.cs (there's no need to add a reference to FontAwesome, the colors still show in the "not found" icon):
public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();
        
        MainPage.Icon = new FontImageSource
        {
            FontFamily = "FASolid",
            Glyph = "\uf130",
            Color = Colors.GreenYellow
        };
        
        MainPage2.Icon = new FontImageSource
        {
            FontFamily = "FASolid",
            Glyph = "\uf130",
            Color = Colors.RosyBrown
        };
    }
}

Update AppShell.xaml to replace the ShellContent with:

<ShellContent
    Title="Home"
    x:Name="MainPage"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />

<ShellContent
    Title="Home2"
    x:Name="MainPage2"
    ContentTemplate="{DataTemplate local:MainPage}"
    Route="MainPage" />
  1. Run, and you'll notice the colors of the two option's icons in the flyout are correctly set to those defined in the code.

Image

  1. Next, update the AppShell.xsml so Shell.FlyoutBehavior="Disabled"
  2. Then replace the ShellContent with:
<TabBar 
    CurrentItem="{Reference MainPage}">
    <ShellContent
        Title="Main"
        x:Name="MainPage"
        ContentTemplate="{DataTemplate local:MainPage}"
        IsVisible="True">
    </ShellContent>
    <ShellContent
        Title="Main2"
        x:Name="MainPage2"
        ContentTemplate="{DataTemplate local:MainPage}"
        IsVisible="True">
    </ShellContent>
</TabBar>
  1. Run, and you'll notice the colors of the two option's icons in the flyout are no longer set to those defined in the code.

Image

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

iOS, macOS

Affected platform versions

Tested on iPhone simulators: 15 Plus (iOS 17.0) & 15 Pro (iOS 17.5)

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-shellShell Navigation, Routes, Tabs, Flyouti/regressionThis issue described a confirmed regression on a currently supported versionplatform/iosplatform/macosmacOS / Mac Catalystregressed-in-8.0.60s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions