maui.net-maui.shell

Shell Backbuttonbehaviour iconoverride fontimagesource


With reference to https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation?view=net-maui-8.0 I see that the IconOverride takes an ImageSource parameter, hence, a FontImageSource.

However, how is it possible to set this FontImageSource through XAML?

<ContentPage ...>    
    <Shell.BackButtonBehavior>
        <BackButtonBehavior Command="{Binding BackCommand}"
                            IconOverride="back.png" />   
    </Shell.BackButtonBehavior>
    ...
</ContentPage>

Solution

  • You can try to define the FontImageSource in ResourceDictionary and then refer it in like IconOverride="{StaticResource sourceKey}".

    <ContentPage.Resources>
    
          <ResourceDictionary>
                <FontImageSource x:Key="sourceKey" FontFamily="yourfontfamily"  Glyph="yourglyph"></FontImageSource>
           </ResourceDictionary>
    </ContentPage.Resources>
    
    <Shell.BackButtonBehavior>
            <BackButtonBehavior IconOverride="{StaticResource sourceKey}">
               
            </BackButtonBehavior>
    </Shell.BackButtonBehavior>