Skip to content

Instantly share code, notes, and snippets.

@mjjames mjjames/WebViewRenderer.cs
Last active May 14, 2018

Embed
What would you like to do?
UWP WebView "Failed Load" Solution Attempt 1
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(WebView), typeof(MyApp.UWP.CustomRenderer.WebViewRenderer))]
namespace MyApp.UWP.CustomRenderer
{
internal class WebViewRenderer : Xamarin.Forms.Platform.UWP.WebViewRenderer, IWebViewDelegate
{
private bool _contentHasLoaded;
private string _html;
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if(e.NewElement == null)
{
return;
}
Control.ContentLoading += (o, args) => _contentHasLoaded = true;
Task.Delay(350).ContinueWith(t =>
{
if (_contentHasLoaded)
{
return;
}
Device.BeginInvokeOnMainThread(() =>
{
LoadHtml(_html, "ms-appx-web:///");
System.Diagnostics.Debug.WriteLine("HTML Load Stalled");
});
});
}
void IWebViewDelegate.LoadHtml(string html, string baseUrl)
{
_html = html;
LoadHtml(html, baseUrl ?? "ms-appx-web:///");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.