White space is not preserving inside Label of TextType Html.

Abraham John 111 Reputation points
2021-03-11T22:37:46.267+00:00

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.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-12T05:44:56.237+00:00

    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.

    0 comments No comments