UWP/C#:如果在 WebView 中打开某些 html 文件,则显示后退按钮

我正在努力从 Cordova 应用程序移植到通用 Windows 平台。此时,我基本上创建了一个容器,其中显示本地 html 文件(它们也是从 Cordova 应用程序移植的)。现在,我想在窗口的左上角添加一个后退按钮,就像任何 UWP 应用程序一样。为此,我使用以下说明:


SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

它工作得很好,但我希望只有当某个 html 文件显示到 webview 时才会出现这个按钮。应该是这样的逻辑:


1) If certain_file.html is loaded

1.1) Show the back button

2) Else

2.1) Hide the back button

我正在使用 Visual Studio 和 Visual C#。你知道我该怎么做吗?


米脂
浏览 211回答 3
3回答

万千封印

更新了代码,现在一切正常!1) 主页.xaml<WebView Name="OnomeWebContainer" Source="ms-appx-web:///www/index.html" DOMContentLoaded="OnomeWebContainer_DOMContentLoaded"></WebView>2) MainPage.xaml.csprivate void OnomeWebContainer_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (args.Uri.LocalPath == "/www/security_auth.html")&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }感谢 Xavier Xie 的帮助!:)
打开App,查看更多内容
随时随地看视频慕课网APP