Radio Buttons

Arthur Van Loo 41 Reputation points
2020-12-17T08:34:27.463+00:00

I was trying to work with radio buttons in Xamarin Forms, but I can't seem to get the text-element appear on my screen.

Developer technologies .NET Xamarin
{count} votes

Accepted answer
  1. Anonymous
    2020-12-17T09:09:02.157+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Here is an workaround to add the text-element appear.

       using Android.Content;  
       using Xamarin.Forms;  
       using Xamarin.Forms.Platform.Android;  
         
       [assembly: ExportRenderer(typeof(RadioButton), typeof(ProjectName.Droid.Renderers.PatchedRadioButtonRenderer))]  
       namespace ProjectName.Droid.Renderers  
       {  
           /// <summary>  
           /// A workaround for the issue in the in-box renderer.  
           /// https://github.com/xamarin/Xamarin.Forms/issues/11700  
           /// </summary>  
           public class PatchedRadioButtonRenderer : RadioButtonRenderer  
           {  
               public PatchedRadioButtonRenderer(Context context) : base(context) {}  
         
               protected override void OnElementChanged(ElementChangedEventArgs<Button> e)  
               {  
                   // Apply text to native radio button  
                   this.Control.Text = e.NewElement.Text;  
         
                   base.OnElementChanged(e);  
               }  
           }  
       }  
    

    Best Regards,

    Leon Lu


    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Arthur Van Loo 41 Reputation points
    2020-12-17T09:25:04.287+00:00

    I don't know what I've done, but I've somehow fixed it. I think it's thanks to @Anonymous

    0 comments No comments

  2. Alessandro Caliaro 4,196 Reputation points
    2020-12-17T09:42:48.26+00:00
    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.