【问题标题】:Universal Windows 10 App. How to use Back Button? VB.NET通用 Windows 10 应用程序。如何使用返回按钮? VB.NET
【发布时间】:2015-10-21 10:54:36
【问题描述】:

在我的应用程序中,如果在子页面上按下后退按钮,应用程序将关闭。

如何在按下后退按钮时调用 Frame.Navigate?

我已经看到了如何在 C# 中执行此操作的示例,但这些示例似乎无法很好地转换为 VB.NET。

下面是我尝试过的一种方法

Private Sub OnHardwareButtonsBackPressed(sender As Object, e As Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested)
        Frame.GoBack()
    End Sub

这会在声明事件类型时打嗝。

还尝试处理事件Windows.UI.Core.SystemNaviationManager,尽管这未能成功拦截后退按钮。

【问题讨论】:

    标签: vb.net win-universal-app uwp


    【解决方案1】:

    正确的语法是:

    Private Sub OnHardwareButtonsBackPressed(sender As Object, e As BackRequestedEventArgs)
        ' Tell the app that you have handled the event
        ' Otherwise, the back button will be processed normally and the app will close
        e.handled = true
    End Sub
    

    然后,附加您的活动:

    AddHandler SystemNavigationManager.GetForCurrentView().BackRequested, AddressOf OnHardwareButtonsBackPressed
    

    【讨论】:

    • 太棒了,这很好用。只需添加一行即可完成此操作。以后我会为其他人进行编辑!
    【解决方案2】:

    为任何寻找 VB.Net 代码以实现应用程序的后退按钮的人修改了上面的建议代码,将 ff 添加到您的 Page2(从您的主页加载的页面):

    1. 添加命名空间:Windows.UI.Core.SystemNavigationManager
    2. 在Page2的Loaded事件中添加这段代码

    GetForCurrentView.AppViewBackButtonVisibility = Visibility.Visible

    AddHandler GetForCurrentView.BackRequested, AddressOf OnAppButtonsBackPressed

    1. 添加处理程序

    私有子 OnAppButtonsBackPressed()

    如果 Frame.CanGoBack 则 Frame.Goback()

    结束子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多