【问题标题】:How to make <a> tag clickable of html in UWP Webview?如何在 UWP Webview 中使 <a> 标签可点击 html?
【发布时间】:2016-07-14 21:21:54
【问题描述】:

我在这里使用 Xaml 和 C#。我正在使用 webview 来显示一些 html,它的工作很完美,但我面临的一个问题是如何使该 Html 内容的标签可点击。

感谢您提前提供任何帮助。

【问题讨论】:

标签: uwp uwp-xaml


【解决方案1】:

当我们点击WebView中的&lt;a&gt;标签时,WebView.NavigationStarting event会被触发。在这种情况下,我们可以得到一个WebViewNavigationStartingEventArgs,其中包含&lt;a&gt;标签中的URI。所以我认为您可以使用它来导航到您的作者个人资料详细信息页面。因为我不知道您的 &lt;a&gt; 标签是如何实现的。这里我只是以一个简单的demo为例。

在 XAML 代码中:

<WebView NavigationStarting="WebView_NavigationStarting" 
         Source="https://blogs.windows.com/buildingapps/2016/07/13/introducing-new-remote-sensing-features-2/" /> 

在代码隐藏中:

private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
    //Add some logic to determine if we need to navigate to AuthorProfileDetailPage
    //and which author's profile need to be shown
    if (args.Uri.AbsoluteUri == @"https://blogs.windows.com/buildingapps/author/windowsappsteam/")
    {
        //Cancel the navigataion in WebView
        args.Cancel = true;
        //Navigate to AuthorProfileDetailPage with the parameter
        //in AuthorProfileDetailPage we can use this parameter to determine which author's profile need to be shown
        this.Frame.Navigate(typeof(AuthorProfileDetailPage), args.Uri.Segments.Last());
    }
}

这是一个简单的示例,您可以自己实现逻辑。希望这会有所帮助。

【讨论】:

  • 非常感谢您的帮助。现在它运行良好。
  • 我正在投票,但它通知我的声誉低于 15。
猜你喜欢
  • 1970-01-01
  • 2012-09-19
  • 1970-01-01
  • 2023-02-26
  • 1970-01-01
  • 2023-04-09
  • 2014-09-19
  • 2022-07-20
  • 2019-05-15
相关资源
最近更新 更多