I am trying to use FontAwesome icons in FlyoutItem
as an icon using FontImageSource
. I had success in Xamarin Forms with following setup, but for some reason in NET MAUI it does not work (at least on Windows?)? I am seeing tab item, but there is no icon no matter what I try. Is there some way to use Font Awesome icons instead of png pictures?
Example of icon I am trying to use: https://fontawesome.com/icons/user?s=solid&f=classic
MauiProgram.cs:
var builder = MauiApp.CreateBuilder();
builder
.UseSkiaSharp(true)
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("FW-Regular-400.otf", "FontAwesomeRegular");
fonts.AddFont("FWBrands-Regular-400.otf", "FontAwesomeBrands");
fonts.AddFont("FW-Solid-900.otf", "FontAwesomeSolid");
});
App.xaml:
<!-- Desktop/Tablet-->
<FlyoutItem Title="Home">
<ShellContent ContentTemplate="{DataTemplate page:HomePage}">
<ShellContent.Icon>
<FontImageSource FontFamily="FontAwesomeSolid" Glyph=""/>
</ShellContent.Icon>
</ShellContent>
</FlyoutItem>
<FlyoutItem Title="Settings">
<ShellContent ContentTemplate="{DataTemplate page:SettingsPage}">
<ShellContent.Icon>
<FontImageSource FontFamily="FontAwesomeSolid" Glyph="user"/>
</ShellContent.Icon>
</ShellContent>
</FlyoutItem>
I have got it working way mentioned below. However currently it seems that this solution is working in NET7, but not in NET6. In NET6 there are no icons visible:
For NET 7
App.xaml:
FontAwesomeIcons.cs: (use some tool available in Internet for such a class generation)
MauiProgram.cs: