你们都很有帮助。
我在集合视图中有一个绑定Text="{Binding PAllText}"的标签。
<CollectionView x:Name="collectionView">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Margin="0" Padding="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<BoxView Color="#333130" Margin="0"></BoxView>
<Label TextType="Html" Grid.ColumnSpan="6" HorizontalOptions="Start" VerticalOptions="Center"
Text="{Binding AllHTMLText}"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>在后面的代码中,我有这样的东西:
PersonClass.AllHTMLText = ("<![CDATA[<p><strong style=\"color:red\"> " + (newLineText.Substring(14, 9)) + "</strong></p><br/>");我也尝试过这样做:
PersonClass.AllHTMLText = ("<p><strong style="color:red"> " + (newLineText.Substring(14, 9)) + "</strong></p><br/>");结果看起来是这样的:
<p style="color:white"><strong style="color:red">Text from a database here</strong></p>我想要的结果是“文本从一个数据库在这里”和它是红色的颜色。
有人能帮助或解释如何在TextType="Html"中使用Xamarin标签吗?
从后面的代码中绑定标签。
Text="{Binding PAllText}"非常感谢!
发布于 2022-02-21 01:51:37
对于xaml页面,您已经设置了TextType="Html",因此只需要将绑定的数据设置为正确的格式。
以下是xaml代码:
<StackLayout>
<Label TextType="Html" HorizontalOptions="Start" VerticalOptions="Center"
x:Name="mytest"/>
</StackLayout>以下是背景代码:
mytest.Text = "<font size='3' color='red'>This is some text!</font>";您可以参考我上面的代码,并使用正确的Html样式来正确显示它。
对于HTML代码中的双引号,您需要用单引号替换它们。
有关字符串替换,请参阅:C#替换。
https://stackoverflow.com/questions/71189253
复制相似问题