Skip to content

Can't use custom image in a MenuItem template #15547

Closed as not planned
Closed as not planned

Description

@Glorfindel83

Description

I'm using a custom DataTemplate for my Shell items. That works fine for FlyoutItem, whose Icon property I can bind too, but the same trick does not work for MenuItem's IconImageSource property.

Screenshot 2023-06-09 at 13 40 52

Steps to Reproduce

  1. Create a new MAUI application, using .NET 6.0
  2. Add an image (service.png) to the Resources/Images folder
  3. Replace AppShell.xaml with the following content:
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="MyMAUIApp.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MyMAUIApp"
    Shell.FlyoutBehavior="Locked"
    FlyoutBackgroundColor="Black"
    Shell.BackgroundColor="Black"
    FlyoutWidth="80">

    <Shell.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="IconTemplate" x:DataType="FlyoutItem">
                <Grid ColumnDefinitions="*" RowDefinitions="Auto,Auto"
                      Padding="3,0,2,0"
                      WidthRequest="{Binding FlyoutWidth, Source={x:Reference Shell}}" 
                      HeightRequest="75">
                    <Image Grid.Column="0" Grid.Row="0"
                           Source="{Binding Icon}"
                           WidthRequest="40"
                           HeightRequest="40"
                           Margin="0,12,0,0">
                    </Image>
                    <Label Grid.Column="0" Grid.Row="1"
                           Margin="0,-3,0,0"
                           Text="{Binding Title}"
                           TextColor="White"
                           FontSize="12"
                           HorizontalOptions="Center"/>
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="MenuItemTemplate" x:DataType="MenuItem">
                <Grid ColumnDefinitions="*" RowDefinitions="Auto,Auto"
                      Padding="3,0,2,0"
                      WidthRequest="{Binding FlyoutWidth, Source={x:Reference Shell}}" 
                      HeightRequest="75">
                    <Image Grid.Column="0" Grid.Row="0"
                           Source="{Binding IconImageSource}"
                           WidthRequest="40"
                           HeightRequest="40"
                           Margin="0,12,0,0" />
                    <Label Grid.Column="0" Grid.Row="1"
                           Margin="0,-3,0,0"
                           Text="{Binding Text}"
                           TextColor="White"
                           FontSize="12"
                           HorizontalOptions="Center"/>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>
    </Shell.Resources>

    <MenuItem Text="Text" IconImageSource="service.png" Shell.MenuItemTemplate="{StaticResource MenuItemTemplate}" />
    <FlyoutItem Title="Title" Icon="service.png" Shell.ItemTemplate="{StaticResource IconTemplate}">
        <ShellContent
            Title="Home"
            ContentTemplate="{DataTemplate local:MainPage}"
            Route="MainPage" />
    </FlyoutItem>


</Shell>
  1. Run the application

If you replace {Binding IconImageSource} with service.png, the icon does show, but I need it to load dynamically from a URL.

Link to public reproduction project repository

https://github.com/Glorfindel83/MAUIBugReports/tree/main/CustomImageMenuItemTemplate

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

iOS 16, Android 33

Did you find any workaround?

Not really; when I replaced the template with one for FlyoutItem, like this:

            <DataTemplate x:Key="MenuItemTemplate" x:DataType="FlyoutItem">
                <Grid ColumnDefinitions="*" RowDefinitions="Auto,Auto"
                      Padding="3,0,2,0"
                      WidthRequest="{Binding FlyoutWidth, Source={x:Reference Shell}}" 
                      HeightRequest="75"
                      BackgroundColor="{DynamicResource Dark}">
                    <Image Grid.Column="0" Grid.Row="0"
                           Source="{Binding Icon}"
                           WidthRequest="40"
                           HeightRequest="40"
                           Margin="0,12,0,0" />
                    <Label Grid.Column="0" Grid.Row="1"
                           Margin="0,-3,0,0"
                           Text="{Binding Title}"
                           TextColor="White"
                           FontSize="12"
                           HorizontalOptions="Center"/>
                </Grid>
            </DataTemplate>

that worked in Debug builds, but not in Release builds.

I have also tried binding it to a property of the Shell's view model, but to no avail.

Activity

  1. added
    t/bug
    on Jun 9, 2023
  2. changed the title [-]Can't use MenuItem's IconImageSource in a template[/-] [+]Can't use custom image in a MenuItem template[/+] on Jun 9, 2023
  3. added
    area-controls-shell
    on Jun 12, 2023
  4. added
    s/needs-repro
    on Jun 14, 2023
  5. Glorfindel83 commented on Jun 16, 2023

    @Glorfindel83
    Author

    Reproduction project added

  6. ghost added
    s/needs-attention
    on Jun 16, 2023
  7. ghost removed
    s/needs-repro
    on Jun 16, 2023
  8. shadowfoxish commented on Aug 31, 2023

    @shadowfoxish

    I think the main issue here is that <MenuItem> is turned into a MenuShellItem and passed into the <Shell.MenuItemTemplate>. So FlyoutItem is definitely not the right x:DataType type for that template.

    MenuShellItem is not public, so you can't data bind correctly to it, and it seems to hide the IconImageSource property. The only workaround I can think of at the moment is, a sucky one, but if you only have one Menu Item, you can set the icon directly as a string in the Template, rather than try to databind to to the MenuItem. Try using ShellItem as the x:DataType and bind your image source to Icon. That might be common enough in between type to make it work.

    I found this related issue, which was closed because Xamarin. xamarin/Xamarin.Forms#13142

    Databindings seem to be handled different in Debug vs Release mode. They seem to be more promiscuous in Debug mode, but in Release mode type/template mismatches will cause crashes.

    image

    https://github.com/dotnet/maui/blob/972b15ed45db627596b3ec0dd206e74624d3689f/src/Controls/src/Core/Shell/MenuShellItem.cs

  9. added
    s/verified
    s/triaged
    on Jan 24, 2024
  10. Zhanglirong-Winnie commented on Jan 24, 2024

    @Zhanglirong-Winnie

    Verified this issue with Visual Studio Enterprise 17.9.0 Preview 3. Can repro on android platforms with sample project.
    https://github.com/Glorfindel83/MAUIBugReports/tree/main/CustomImageMenuItemTemplate
    image

  11. 3 remaining items

  12. tentom commented on Nov 20, 2024

    @tentom

    I seem to have the same issue when I have a binding for the Text proprety as well of the MenuItem

  13. Barry-Theunissen commented on Feb 3, 2025

    @Barry-Theunissen

    Any fix for this yet? I have the same issue

  14. Grzegorz1223 commented on Feb 12, 2025

    @Grzegorz1223

    ATM there is no way of using MenuItemTemplate with precompiled bindings. Can this be take in account for MAUI as well since the situation is exactly the same? xamarin/Xamarin.Forms#13142

  15. b12kab commented on Mar 7, 2025

    @b12kab

    I am in the same place as all of the above people and presumably others just starting to work on .net9. As noted by @Grzegorz1223 the Xamarin issue is the same as this one.

    When can MenuShellItem be changed from an internal class to a public one?

  16. KHALED-gtf commented on Jun 10, 2025

    @KHALED-gtf

    I have got the same issue

  17. sebdevlab commented on Jul 21, 2025

    @sebdevlab

    +1. Also facing this same issue! We want to implement a flyout menu that is not connected to the bottom tabbar. So we can't use FlyoutItems because the ShellContent will interfere with the ShellContent from the tabbar. Therefore using MenuItems but can't set the icons through the IconImageSource binding with the MenuItemTemplate...

  18. sebdevlab commented on Jul 21, 2025

    @sebdevlab

    I've found a solution. In your Shell.MenuItemTemplate remove the x:DataType binding from the DataTemplate. Then for the Source of the Image you can set the Binding to Icon instead of IconImageSource. Removing the DataType will make it possible to set the binding to the Icon attribute of the FlyoutItem instead of the MenuItem. They both are part of the Shell so it will render it

    Image
  19. kosaku-hayashi commented on Jun 1, 2026

    @kosaku-hayashi

    You can work around this by using the FlyoutContent property to replace the entire Flyout menu section with custom content. You can either write MenuItem elements directly, or use FlyoutContentTemplate to enable compiled bindings.

    https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/flyout?view=net-maui-10.0#replace-flyout-content

  20. added
    s/try-latest-version
    on Aug 13, 2026
  21. dotnet-policy-service commented on Aug 13, 2026

    @dotnet-policy-service
    Contributor

    Hi @@Glorfindel83. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

    You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

    This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

  22. dotnet-policy-service commented on Aug 13, 2026

    @dotnet-policy-service
    Contributor

    Hi @Glorfindel83. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

    You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

    This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

  23. removed
    s/try-latest-version
    on Aug 14, 2026
  24. kubaflo commented on Oct 10, 2026

    @kubaflo
    Contributor

    Thank you for taking the time to report this and share the details.

    We requested a check on the latest version on August 13, 2026, and there has been no subsequent human follow-up in this thread. We are closing this report as not planned at this time because the requested current-version confirmation has not arrived and we are not scheduling further investigation from this thread.

    This is a backlog-prioritization decision, not evidence that the reported behavior is fixed or that the original report lacked value. If the issue remains a blocker on a supported current .NET MAUI version, please comment here with that version and the reproduction result so we can reassess it. An existing sample, attachment, code snippet, or repository test can be reused; a new repository is not required.

  25. locked and limited conversation to collaborators on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-shellplatform/androidplatform/ioss/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions