How to load local HTML file in xamarin forms web view

I am trying to load an html file that is in the same way as the class I am working with. Through the web view in xamarin forms, when I launch the application, I get a white screen and my code is not loading here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace App.Plan
{
    public partial class Tornado : ContentPage
    {
        public Tornado()
        {
            InitializeComponent();
            var browser = new WebView
            {
                Source = "local.html"
};
    }
    }
}
+2
source share
2 answers

Xamarin has documents regarding this:

https://developer.xamarin.com/guides/xamarin-forms/user-interface/webview/

var browser = new WebView();
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html><body>
  <h1>Xamarin.Forms</h1>
  <p>Welcome to WebView.</p>
  </body></html>";
browser.Source = htmlSource;
+1
source

Here is the official sample on github

WorkingWithWebview

tabs.Children.Add (new LocalHtml {Title = "Local" });
tabs.Children.Add (new LocalHtmlBaseUrl {Title = "BaseUrl" });
tabs.Children.Add (new WebPage { Title = "Web Page"});
tabs.Children.Add (new WebAppPage {Title ="External"});

The second tab may help.

0
source

All Articles