本文介绍了当 URL 无效时,UWP Webview NavigationStarting 事件处理程序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

订阅EvenHandler:

wv.NavigationStarting += webView_NavigationStarting;

EvenHandler 实现

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;
}

当 URL 有效时,它可以完美导航,否则不会调用 EvenHandler.

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

下面的弹出窗口显示:

推荐答案

您可以使用 WebView.UnsupportedUriSchemeIdentified 处理未知 uri 的事件.

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
}

请注意,如果链接无效,将改为引发 WebView.NavigationFailed

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

这篇关于当 URL 无效时,UWP Webview NavigationStarting 事件处理程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 16:09