简体   繁体   中英

Xamarin Forms - WinPhone - Formatted text

My app needs to run on Android, iOS and WinPhone 8.1. It needs to have a page with a long text that include a lot of format:

bold
bullet list
link (http, mail, phone)

Because it has to run on all 3 platforms, I tried to create an HTML string in order to send it to a WebView like this :

MyWebView.Source = new HtmlWebViewSource {Html = stringHtml }; 

So I can use <b> for bolds, <ul> for bullet lists, <a> for links.

Because I need also a custom font and specific size, in my html string there is a new style with all these the informations.
It works.... but with 2 problems on Windows Phone:

  1. all the bullet list font size are really smaller than the rest of text
  2. all the pages show a blank webview, but if I reload it (a lot of times) or wait 3/4 seconds then it shows the content

Any idea about these problems?

And if there's another solution different from WebView... it's welcome!

Xamarin.Forms includes a FormattedText property in the Label (this guide should help you to understand it: Xamarin.Forms FormattedText ). But there are some things you want to do that can't be done with it, and these are:

  • FormattedText doesn't have links, but if I'm not mistaken, if you use links in a WebView, they will only work within that WebView, so the link will be open in the same space as your text.
  • FormattedText doesn't have a bullet list. You can go around this problem adding the ASCII bullet character (in windows: Hold ALT and press the number 7) and some spaces to indent the paragraph.

The rest of what you want (bold, italic, color changes, etc.) FormattedText has.

Hope it helps! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM