Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Unable to bind Glyph property in FontImageSource of ToolbarItem #12700

Open
maxkoshevoi opened this issue Nov 1, 2020 · 5 comments
Open

Comments

@maxkoshevoi
Copy link

Description

Original discussion: https://forums.xamarin.com/discussion/180852/why-glyph-property-in-fontimagesource-doesnt-bind

This code doesn't produce any errors, but Glyph is always empty (getter of MyIcon is newer executed):

<ContentPage.ToolbarItems>            
    <ToolbarItem>
        <ToolbarItem.IconImageSource>
            <FontImageSource Glyph="{Binding MyIcon}" FontFamily="{x:StaticResource MaterialFontFamily}" />
        </ToolbarItem.IconImageSource>
    </ToolbarItem>
</ContentPage.ToolbarItems>

Static binding works fine.

Steps to Reproduce

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

Expected Behavior

I can see binded icon.

Actual Behavior

ToolbarItem has no icon

Basic Information

  • Version with issue: 4.8.0.1560
  • Last known good version: -
  • IDE: VS2019
  • Platform Target Frameworks:
    • iOS: -
    • Android: 11
    • UWP: -
  • Android Support Library Version: -
  • Nuget Packages:
  • Affected Devices:

Screenshots

image

Reproduction Link

Thanks igorkr_10.

GlyphToolbarItem.zip

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;
    }
}
@maxkoshevoi maxkoshevoi added s/unverified New report that has yet to be verified t/bug 🐛 labels Nov 1, 2020
@samhouts samhouts added this to New in Triage Nov 1, 2020
@rmarinho rmarinho added a/fonticon a/toolbar p/iOS 🍎 p/Android and removed s/unverified New report that has yet to be verified labels Nov 3, 2020
@rmarinho rmarinho moved this from New to Needs Estimate in Triage Nov 3, 2020
@acaliaro
Copy link

acaliaro commented May 6, 2021

Hi guys, some news on this?

@KeithBoynton
Copy link

I just burned a few hours on this too until I came across this bug. Definitely needs fixing.

@nZeus
Copy link

nZeus commented Nov 12, 2021

The binding worked for us, after we changed the value from &#xf0c9; format to \uf0c9

@krunalc
Copy link

krunalc commented Nov 14, 2021

@nZeus's fix above worked for me.

@FlorianAuer
Copy link

@nZeus' fix works like a charm. Keep in mind: No ';' and all lowercase.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Triage
  
Needs Estimate
Development

No branches or pull requests

7 participants