Unable to bind `Glyph` property in `FontImageSource` of `ToolbarItem`

See original GitHub issue

Description

Original discussion: https://forums.xamarin.com/discussion/180852/why-glyph-property-in-fontimagesource-doesnt-bind Xamarin issue: https://github.com/xamarin/Xamarin.Forms/issues/12700

This code doesn’t produce any errors, but Glyph is always empty:

<ContentPage.ToolbarItems>
    <ToolbarItem IconImageSource="{FontImageSource Glyph={Binding MyIcon}, FontFamily=MaterialDesignIcons}" />
</ContentPage.ToolbarItems>

Static binding works fine. Code above also works if it’s added via Hot Reload (but after proper app reload icon is gone again)

image

Steps to Reproduce

  1. Add ToolbarItem to your page
  2. SpecifyIconImageSource to it as FontImageSource with binded Glyph

Link to public reproduction project repository

Remove the converter and start the app: https://github.com/maxkoshevoi/NureTimetable/blob/5f67cadbb78bc3c37df4985adf8c4ce3a936b4a0/NureTimetable/UI/Views/Timetable/TimetablePage.xaml#L20

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All (tested on 13)

Did you find any workaround?

Thanks Saskia.

<ToolbarItem IconImageSource="{Binding MyIcon, Converter={converters:ToolbarIconValueConverter}}" />
public class ToolbarIconValueConverter : IValueConverter, IMarkupExtension
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return new FontImageSource
        {
            FontFamily = (OnPlatform<string>)Application.Current.Resources["MaterialFontFamily"],
            Glyph = (string)value
        };
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        return this;
    }
}

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
MichaelAzzercommented, Nov 9, 2022

Sorry I tested it with regular image not with toolbar, but it’s not working with toolbar I’m sorry for that

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows

From: Maksym @.> Sent: Wednesday, November 9, 2022 10:32 AM To: @.> Cc: Michael @.>; @.> Subject: Re: [dotnet/maui] Unable to bind Glyph property in FontImageSource of ToolbarItem (Issue #10186)

Yes it’s working without converter

Could you please share a sample project? It doesn’t work on my side as I’ve described here: #10186 (comment)https://github.com/dotnet/maui/issues/10186#issuecomment-1268835353

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/maui/issues/10186#issuecomment-1308391797, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADRJJRWYWAM3APJ7D2AHCS3WHNOTRANCNFSM6AAAAAAQPE72UI. You are receiving this because you were mentioned.Message ID: @.***>

1reaction
marcmognolcommented, Sep 17, 2022

My bad, you were talking about dynamic binding for glyph. Sorry

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Glyph property in FontImageSource doesn't bind?
Hi community. I have a strange behavior with FontImageSource. I can't get property binded to Glyph. <ContentPage.
Read more >
Issue with FontImageSource Glyph when using a Binding
Using Xamarin Forms 5 and Visual Studio 2022. I have added the materialdesignicons-webfont.ttf to a Fonts folder of the PCL project only and ......
Read more >
Xamarin Unable to change the color of the ToolBarItem ...
I have the following XAML code which gives me a toolbar and unfortunately, it doesn't change the color of the icon. Code <ToolbarItem...
Read more >
FontImageSource Glyph icon with data binding, only ...
My problem is, that not the actual Glyph icon, but its unicode (a simple string) is displayed on the UI. The toggle favorite...
Read more >
Adding an icon font to your Xamarin Forms apps
Create glyph resources to identify each icon ysou want to use. Let's take an example. ... Right-click on the font, then select Properties....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found