如何以 xamarin 形式显示 html 格式的文本 [英] How can I show text with html format in xamarin forms
问题描述
我使用 json 处理网络服务,并获得 html 格式的文本.我希望我的文本具有超链接和一些其他属性,我可以从 html 标签(等粗体)中找到这些属性.
I work on webservice with json and i get text with html format. I want my text have hyperlinks and some other properties where i find from html tags (etc. bold).
我尝试在 WebView 源代码中绑定我的 html 字符串,但 WebView 每次都是空白的.我用这个代码
I try binding my html string in WebView source but WebView is every time blank. I use this code
var browser = new WebView();
var htmlSource = new HTMLWebViewSource();
htmlSource.Html = MyItem.Article;
browser.Source = htmlSource;
MyItem.Article 字符串是这样的
MyItem.Article string is like this
我想要这样的东西在 Label 里面,在 ListView os 里面是这样的.
I want something like this inside Label where is inside ListView os something like that.
我该怎么做?
推荐答案
这应该对你有用
string htmlText = MyItem.Article.ToString().Replace(@"", string.Empty);
var browser = new WebView ();
var html = new HtmlWebViewSource {
Html = htmlText
};
browser.Source = html;
因为 Xamarin.Forms.HtmlWebViewSource.HTML
需要纯 HTML.使用它,您可以在本文 http: 的帮助下创建 Xamarin.Forms 用户控件://blog.falafel.com/creating-reusable-xaml-user-controls-xamarin-forms/干杯..!
Because Xamarin.Forms.HtmlWebViewSource.HTML
expect a pure HTML. Using this you can create a Xamarin.Forms user control with the help of this article http://blog.falafel.com/creating-reusable-xaml-user-controls-xamarin-forms/ Cheers..!
这篇关于如何以 xamarin 形式显示 html 格式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!