In Xamarin, how to handle the WKWebView ShouldStartLoad event
1 answer
You need to override DecidePolicy in your WKNavigationDelegate subclass.
public class WebNavigationDelegate : WKNavigationDelegate
{
...
public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
var url = navigationAction.Request.Url;
if (true) //Whatever your test happens to be
{
decisionHandler(WKNavigationActionPolicy.Allow);
}
else
{
decisionHandler(WKNavigationActionPolicy.Cancel);
}
}
...
}
Then set the webview navigation delegate to your new class.
_webView.NavigationDelegate = new WebNavigationDelegate(this);
+2
source to share