AISAC
AISAC

Reputation: 931

Bind breakline symbol to Label.Text

When binding a Label.Text have tried many ways: \n \r but none of them are being displayed as breakline I refuse to believe I will need to dynamically create a Custom control to generate spans on numbers of breakline symbol... is there any easier/simpler approach ?

What I've tried:

The xaml: <Label Text="{Binding BreaklineText}"/>

It should be displayed on my view as Text first line Text second line

Upvotes: 0

Views: 669

Answers (3)

Will Autio
Will Autio

Reputation: 74

I built on @Motumbo and set System.Environment.NewLine to a variable like

var nl = System.Environment.NewLine;

then I could write variations on:

string text = "some text" + nl + "text on newline";

Also found that "\r\n" works on Droid and UWP. Did not have iOS to test. So:

string text = "some text\r\ntext on newline";

worked for me.

Upvotes: 0

AISAC
AISAC

Reputation: 931

It's not the optimal solution since I wanted to find a symbol that could be interpreted as BreakLine on XAML, but it will do the job.

string BreaklineText = "Text first line\nText second line".Replace("\n", System.Environment.NewLine);

Upvotes: 1

Morse
Morse

Reputation: 9115

using Ascii equivalent &#10; in XAML should work, you have missed ;

<Label Text="Text first line&#10;Text second line"/>

Upvotes: 0

Related Questions