Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kevinjohnobrien opened this issue Jan 8, 2025 · 2 comments · May be fixed by #26757
Open
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout i/regression This issue described a confirmed regression on a currently supported version s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@kevinjohnobrien
Copy link

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

@kevinjohnobrien kevinjohnobrien added the t/bug Something isn't working label Jan 8, 2025
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@jfversluis jfversluis added area-controls-shell Shell Navigation, Routes, Tabs, Flyout potential-regression This issue described a possible regression on a currently supported version., verification pending labels Jan 8, 2025
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed i/regression This issue described a confirmed regression on a currently supported version and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels Jan 9, 2025
@Zhanglirong-Winnie
Copy link

This issue has been verified Visual Studio Code 1.96.2 (9.0.22 & 9.0.10). Can repro this issue on iOS platform. On 8.0.40 works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout i/regression This issue described a confirmed regression on a currently supported version s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
3 participants