title: How to underline label with underline effect in Xamarin Forms?
body: <p>I followed <a href="http://smstuebe.de/2016/08/29/underlinedlabel.xamarin.forms/" rel="noreferrer">this</a> tutorial to create underline effect. However, when my page starts it breaks without exception being caught. Has anyone managed to create underline effect? Here is a code:</p>
  
  <p>UnderlineEffect.cs:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace XX.CustomForms
  {
      public class UnderlineEffect : RoutingEffect
      {
          public const string EffectNamespace = "XX.CustomForms";
  
          public UnderlineEffect() : base($"{EffectNamespace}.{nameof(UnderlineEffect)}")
          {
          }
      }
  }
  </code></pre>
  
  <p>UnderlineLabel_Droid.cs:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[assembly: ResolutionGroupName(UnderlineEffect.EffectNamespace)]
  [assembly: ExportEffect(typeof(UnderlineEffect), nameof(UnderlineEffect))]
  namespace XX.Droid.Renderers
  {
      public class UnderlineEffect : PlatformEffect
      {
          protected override void OnAttached()
          {
              SetUnderline(true);
          }
  
          protected override void OnDetached()
          {
              SetUnderline(false);
          }
  
          protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
          {
              base.OnElementPropertyChanged(args);
  
              if (args.PropertyName == Label.TextProperty.PropertyName || args.PropertyName == Label.FormattedTextProperty.PropertyName)
              {
                  SetUnderline(true);
              }
          }
  
          private void SetUnderline(bool underlined)
          {
              try
              {
                  var textView = (TextView)Control;
                  if (underlined)
                  {
                      textView.PaintFlags |= PaintFlags.UnderlineText;
                  }
                  else
                  {
                      textView.PaintFlags &amp;= ~PaintFlags.UnderlineText;
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Cannot underline Label. Error: ", ex.Message);
              }
          }
      }
  }
  </code></pre>
  
  <p>And my xaml:</p>
  
  <pre><code>    xmlns:custom="clr-namespace:XX.CustomForms;assembly=XX"
  
      &lt;Label Text="Privacy Notice" HorizontalTextAlignment="Center" &gt;
          &lt;Label.Effects&gt;
              &lt;custom:UnderlineEffect /&gt;
          &lt;/Label.Effects&gt;
      &lt;/Label&gt;
  </code></pre>