11thal11thal
11thal11thal

Reputation: 333

Multiline button in Xamarin? 
 is not working

Using 
 is not working. Instead my button only appears to say "First Line."

<Button Text="First Line&#x0a;Second Line"/> 

Am I doing this incorrectly? Is there another simple way to make the text go onto the second line?

Upvotes: 0

Views: 1253

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 14956

I test it on Android,it works well,Did you run on ios ? I think this is mainly a problem with iOS because Android will wrap the text by default.

If you want run on ios,you could use customrenderer to achieve this.

[assembly: ExportRenderer(typeof(Button), typeof(iosbutton))]
namespace EntryCa.iOS
{
  class iosbutton :ButtonRenderer
  {

    protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
    {
        base.OnElementChanged(e);
        if (Control != null)
        {
            Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;
            Control.TitleLabel.Lines = 0;
            Control.TitleLabel.TextAlignment = UITextAlignment.Center;
        }
    }
  }
}

Upvotes: 2

Related Questions