question

AbrahamJohn-8020 avatar image
0 Votes"
AbrahamJohn-8020 asked ·

White space is not preserving inside Label of TextType Html.

Let me write my code:

 <Label Text="{Binding text}" TextType="Html"/>

If,

 text = "<pre>Hello      user<BR/>How     are you</pre>"

But the output is shown as:

Hello user
How are you

So how we can preserve all white spaces inside pre tag.





dotnet-xamarinforms-xaml
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ·

Hello,

Welcome to Microsoft Q&A!

The Html style does not support <pre> based on my test .

I even tried to use HtmlLabelPlugin , but still no luck , same result .

If you want to display the html perfectly , I suggest you use WebView .

Code


var browser = new WebView();
            var htmlSource = new HtmlWebViewSource();
            htmlSource.Html = @"<html><body>
  <pre>Hello      user<BR/>How     are you</pre>
  </body></html>";
            browser.Source = htmlSource;

            Content = browser;


Result

77035-capture.png


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



capture.png (18.2 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.