Nan*_*tte 3 html xamarin xamarin.forms
我正在用 Xamarin Forms 为我的网站制作一个移动应用程序。在数据库中,我有一个包含一些 html 的字段。
我正在使用https://github.com/matteobortolazzo/HtmlLabelPlugin但我似乎无法设置我的 html 样式。
这是我的代码:
public string Body { get; set; }
public string BodyStyled => $"<!DOCTYPE html><html>" +
$"<head>" +
$"<style>" +
$"p {{margin-bottom: 5px;}}" +
$"</style>" +
$"</head>" +
$"<body>" +
$"{Body}" +
$"</body>" +
$"</html>";
<htmlLabel:HtmlLabel
Grid.Row="0"
VerticalOptions="Center"
TextColor="{ DynamicResource BaseTextColor }"
Text="{ Binding Detail.BodyStyled }"/>
Run Code Online (Sandbox Code Playgroud)
HTML 被执行,但 p {margin-bottom: 5px;} 被打印在文本上方。
我该如何解决这个问题?谢谢!
小智 5
使用最新版本的 Xamarin 表单
<Label TextType="Html">
<![CDATA[
This is <strong style="color:red">HTML</strong> text.
]]>
</Label>
Run Code Online (Sandbox Code Playgroud)
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/label