UWP Webview NavigationStarting event handler is not working when URL is not Valid

拥有回忆 提交于 2019-12-24 10:38:33

问题


Subscribe EvenHandler:

wv.NavigationStarting += webView_NavigationStarting;

EvenHandler Implementation

private static void webView_NavigationStarting(object sender, WebViewNavigationStartingEventArgs args)
{
    var url = args.Uri.AbsoluteUri.Substring(args.Uri.AbsoluteUri.LastIndexOf("/") + 1);
    int parameterCount = url.Split('_').Length;
}

When URL is valid it navigates perfectly fine, otherwise EvenHandler was not called.

And the pop up below shows:


回答1:


You can use the WebView.UnsupportedUriSchemeIdentified event to handle unknown uri's.

private void webView_OnUnsupportedUriSchemeIdentified(WebView sender, WebViewUnsupportedUriSchemeIdentifiedEventArgs args)
{
    args.Handled = true;

    // up to you what to do with args.Uri
}

Be aware that if the link is invalid, the WebView.NavigationFailed will be raised instead!



来源:https://stackoverflow.com/questions/43065107/uwp-webview-navigationstarting-event-handler-is-not-working-when-url-is-not-vali

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!