简体   繁体   English

Xamarin表单-WinPhone-格式化文本

[英]Xamarin Forms - WinPhone - Formatted text

My app needs to run on Android, iOS and WinPhone 8.1. 我的应用程序需要在Android,iOS和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) 链接(http,邮件,电话)

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 : 因为它必须在所有3个平台上运行,所以我尝试创建一个HTML字符串以将其发送到这样的WebView:

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

So I can use <b> for bolds, <ul> for bullet lists, <a> for links. 因此,我可以将<b>用作粗体,将<ul>用作项目符号列表,将<a>用作链接。

Because I need also a custom font and specific size, in my html string there is a new style with all these the informations. 因为我还需要自定义字体和特定大小,所以在我的html字符串中,所有这些信息都有一种新样式。
It works.... but with 2 problems on Windows Phone: 它可以工作...。但是在Windows Phone上有2个问题:

  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 所有页面都显示一个空白的Webview,但是如果我重新加载它(很多次)或等待3/4秒,则它会显示内容

Any idea about these problems? 对这些问题有任何想法吗?

And if there's another solution different from WebView... it's welcome! 而且,如果还有不同于WebView的解决方案,欢迎您!

Xamarin.Forms includes a FormattedText property in the Label (this guide should help you to understand it: Xamarin.Forms FormattedText ). Xamarin.Forms在Label中包含FormattedText属性(本指南应帮助您理解它: 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没有链接,但是如果我没记错的话,如果您在WebView中使用链接,则它们只能在该WebView中使用,因此链接将在与文本相同的空间中打开。
  • FormattedText doesn't have a bullet list. FormattedText没有项目符号列表。 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. 您可以解决此问题,添加ASCII项目符号字符(在Windows中:按住ALT并按数字7)和一些空格以使段落缩进。

The rest of what you want (bold, italic, color changes, etc.) FormattedText has. 您想要的其余内容(粗体,斜体,颜色更改等)都具有FormattedText。

Hope it helps! 希望能帮助到你! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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