ImageButton FontImageSource.Glyph and FontImageSource.Color binding in csharp

Alessandro Caliaro 4,181 Reputation points


I have an ImageButton and I set a static source:

            iconCancellaOModificaQuantitaOBarcode.Source = new FontImageSource
                Glyph = Library.IconaCancella,
                FontFamily = "ionicons",
                Color = Color.Red,
                Size = ICON_SIZE

I would like to have Glyph and Color's FontImageSource binding, but I see only ImageButton.SourceProperty.
It seems that is possible in xaml:


                    Glyph="{Binding SaveIconFont}"
                    FontFamily="{StaticResource FontAwesomeFreeSolid}"


Is not possible to bind Glyph and Color in csharp without bind all the "Source"?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points


    Welcome to our Microsoft Q&A platform!

    To set data binding in csharp, try using the BindableObjectExtensions.SetBinding method.

    Check the code:

       var iconSource = new FontImageSource  
           Size = ICON_SIZE,  
           FontFamily = "ionicons  
       iconSource.SetBinding(FontImageSource.GlyphProperty, "name");  
       iconSource.SetBinding(FontImageSource.ColorProperty, "name");  
       var imageButton = new ImageButton { Source = iconSource };  

    Best Regards,

    Jarvan Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points
                this.imagebutton.Source = new FontImageSource() { FontFamily = "ionicons" };  
                this.imagebutton.Source.SetBinding(FontImageSource.GlyphProperty, "Glyph");  
                this.imagebutton.Source.SetBinding(FontImageSource.ColorProperty, "Color");  

    this works!

    Thanks @JarvanZhang

    0 comments No comments