I would like to be able to add some HTML into a Xamarin.Forms page? Is this possible? Also is it possible to add this as part of a label?
If you want full-blown html support, then Xamarin forms WebView
would be way to go. But if you want some basic formatting support in Label
as it's native counter-parts (TextView
in android, and UILabel
in iOS) do, you can implement renderers for that.
Forms control
public class HtmlLabel : Label
{
public static readonly BindableProperty HtmlProperty =
BindableProperty.Create(
"Html", typeof(string), typeof(HtmlLabel),
defaultValue: default(string));
public string Html
{
get { return (string)GetValue(HtmlProperty); }
set { SetValue(HtmlProperty, value); }
}
}
iOS renderer
[assembly: ExportRenderer(typeof(HtmlLabel), typeof(HtmlLabelRenderer))]
namespace HtmlLabelApp.iOS
{
public class HtmlLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs
Android renderer
[assembly: ExportRenderer(typeof(HtmlLabel), typeof(HtmlLabelRenderer))]
namespace HtmlLabelApp.Droid
{
public class HtmlLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs
Main Title
A sub-title
This is some html. Look, here\'s an underline.
Look, this is emphasized. And here\'s some bold.
This is a UL list:
- One
- Two
- Three
This is an OL list:
- One
- Two
- Three
]]>