如何以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里面是这样的东西.
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屋!