Reputation: 1018
Am trying to justify text in Label Xamarin Forms but couldnt ,
how to justify the text (not styling justify only) same like a picture without using webview
I have attached my code but its justify left only
string strText="MY LONG TEXT IS GOING HERE";
var lblMSG = new Label {TextColor = Color.Black };
lblMSG.Text=strText;
lblMSG.LineBreakMode = LineBreakMode.WordWrap;
lblMSG.HorizontalOptions = LayoutOptions.Fill;
lblMSG.HorizontalTextAlignment = TextAlignment.Start;
lblMSG.VerticalTextAlignment = TextAlignment.Center;
StackLayout stk= new StackLayout { Children = { lblMSG}, BackgroundColor = Color.White ,HorizontalOptions =LayoutOptions.FillAndExpand }
Upvotes: 4
Views: 7185
Reputation: 4652
If the question is about stretching the multi-line text to full width (text must touch left and right sides of the block), you can use platform renderer. See this reply.
Upvotes: 1
Reputation: 865
Instead of using a label. I used a HtmlWebViewSource.
An example is below:
XAML:
<StackLayout x:Name="webViewLayout"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<!-- view codebehind for WebView for overview text -->
</StackLayout>
Code Behind of XAML (viewModel.Model.Content = strText in your case):
var browser = new WebView();
browser.HorizontalOptions = LayoutOptions.FillAndExpand;
browser.VerticalOptions = LayoutOptions.FillAndExpand;
var source = new HtmlWebViewSource();
var text = "<html>" +
"<body style=\"text-align: justify;\">" +
String.Format("<p>{0}</p>", viewModel.Model.Content) +
"</body>" +
"</html>";
source.Html = text ;
browser.Source = source;
webViewLayout.Children.Add(browser);
Upvotes: 4