Last active
May 14, 2018 22:50
-
-
Save mjjames/e0c2e261ba4095ec5a1b51253983a608 to your computer and use it in GitHub Desktop.
UWP WebView "Failed Load" Solution Attempt 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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