Skip to content

Instantly share code, notes, and snippets.

@mjjames
Last active May 14, 2018 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjjames/e0c2e261ba4095ec5a1b51253983a608 to your computer and use it in GitHub Desktop.
Save mjjames/e0c2e261ba4095ec5a1b51253983a608 to your computer and use it in GitHub Desktop.
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