I have a label with TextType="Html" in my xamarin forms App. I am trying to bind the following html text. Get help with your health related questions <strong style="color:#007ABC;">when you sign up to become an awesome holder.</strong>. The weird issue I am facing is when I put this text directly into Xaml, the text getting rendered properly with the color and everything. But when I try to bind this from backend, ie; from a string property in viewmodel, the text will not get rendered correctly. Please refer the screenshot attached. Is there any internal conversion happening? How to tackle this issue because I have to get this from the API. Any help is appriciated.

1 Answer
You may refer to this document Display HTML. And you could see the differences between using XAML and using code behind.
< in XAML convert to < in code behind
" in XAML convert to \" in code behind. (Note: The double quote characters in the HTML have to be escaped using the \ symbol.)
So the origin string works for XAML may equal to this in code behind:
Get help with your health related questions <strong style=\"color:#007ABC;\">when you sign up to become an awesome holder.</strong>";
So the easiest way i think is that you could use a String.Replace method to convert the string.
For example,
CodeBehindString = XAMLString.Replace("<","<").Replace(">",">").Replace(""","\"");
Or you may use Xamarin.Forms Binding Value Converters as Jason said.
Hope it helps.
1 Comment
Anand
Thank you. This worked System.Net.WebUtility.HtmlDecode(htmlstring);
<into<