I have a need where I need to dynamically keep changing the underline status of a particular Text in Xamarin Forms label.
After referring multiple posts on how to underline a label, I tried both the options, creating a custom renderer as well as using Effects. The text underlines fine. However the problem is that the underline status of the Label doesn't update. This problem however is only in iOS, Android works fine.
I created a bindable property HasUnderline in my Custom Label class in Xamarin Forms. The OnElementPropertyChange method in iOS is fired within the CustomRenderer. I then also change the underline property of the control using
text.AddAttribute(UIStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
However, the same is not reflected in the UI.
After so many hours of my head banging, I finally, however, did notice that if I change the value of the Text, the underline immediately reflects. So it appears the changing the underline property doesn't reflect until something in the content of the text is changed. But I don't want to change the text while adding/removing the underline.
I have uploaded the sample on GitHub at github.com/kuntalkishore/XFUnderline.git Note that clicking on button causes the Toggle underline to be invoked in iOS custom renderer however the underline toggle has no effect. Once you uncomment the line 25,26 in MainPage.xaml.cs the underline starts working!
How can I solve this issue?