Image inside label xamarin forms

simone pittiglio 1 Reputation point
2021-10-20T10:10:58.15+00:00

I need to insert an image inside a label in Xamarin forms. Sample: "Click this image {img.png} to add item"

I tryied to convert my png to Font and use it as Span inside the label but I failed (I don't know how to use the ttf file in the span). Any other suggestion? I prefer to avoid html view

Thank's a lot

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. cristopheB 551 Reputation points
    2021-10-20T10:21:10.133+00:00

  2. JarvanZhang 23,971 Reputation points
    2021-10-21T03:01:56.673+00:00

    Hello @simone pittiglio ,​

    Welcome to our Microsoft Q&A platform!

    I need to insert an image inside a label in Xamarin forms. Sample: "Click this image {img.png} to add item"

    To display the content as above, try using a StackLayout to wraps the views and set the Orientation to Horizontal. For the image's click event, you could add tap gesture to the image control.

    Here is the sample code, you could refer to it.

       <StackLayout Orientation="Horizontal">  
           <Label Text="Click this image"/>  
           <Image Source="yali" HeightRequest="25">  
               <Image.GestureRecognizers>  
                   <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>  
               </Image.GestureRecognizers>  
           </Image>  
           <Label Text="to add the item"/>  
       </StackLayout>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.