Reputation: 21
You all are so helpful.
I have a Label that is bound Text="{Binding PAllText}"
inside a collection view.
<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>
Then in the code behind I have something like this:
PersonClass.AllHTMLText = ("<![CDATA[<p><strong style=\"color:red\"> " + (newLineText.Substring(14, 9)) + "</strong></p><br/>");
Ive also tried this:
PersonClass.AllHTMLText = ("<p><strong style="color:red"> " + (newLineText.Substring(14, 9)) + "</strong></p><br/>");
And the result literally Looks like this:
<p style="color:white"><strong style="color:red">Text from a database here</strong></p>
I want the result to be "Text from a database here" and for it to be Red in color.
Can someone help or explain how to use the Xamarin Label with TextType="Html"
With binding the Label from the code behind.
Text="{Binding PAllText}"
Thanks so much!!!
Upvotes: 1
Views: 649
Reputation: 1686
For xaml pages, you have already set TextType="Html"
, so you just need to set the bound data to the correct format.
Here is the xaml code:
<StackLayout>
<Label TextType="Html" HorizontalOptions="Start" VerticalOptions="Center"
x:Name="mytest"/>
</StackLayout>
Here is the background code:
mytest.Text = "<font size='3' color='red'>This is some text!</font>";
You can refer to my code above and use the correct Html style to display it correctly.
For double quotes in HTML code, you need to replace them with single quotes.
For string replacement, please refer to: C# Replace.
Upvotes: 1