Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows runtime 处理后退按钮Windows 8.1通用应用程序_Windows Runtime_Windows Phone 8.1_Win Universal App - Fatal编程技术网

Windows runtime 处理后退按钮Windows 8.1通用应用程序

Windows runtime 处理后退按钮Windows 8.1通用应用程序,windows-runtime,windows-phone-8.1,win-universal-app,Windows Runtime,Windows Phone 8.1,Win Universal App,我正在将我的应用程序从WindowsPhone8Silverlight更新到Windows8.1RT(我想这就是所谓的) 我刚刚创建了第二个页面,当我转到并按下后退按钮时,它将退出我的应用程序,而不是返回第一个页面 我不知道为什么会发生这种情况,默认行为会一直持续到最后一页,对吗 我找不到如何重写back button事件以进行Frame.GoBack()调用 这是一个开发预览错误还是我遗漏了什么?放入第二页的构造函数:(SecondPage.xaml.cs) 然后定义eventhandler函

我正在将我的应用程序从WindowsPhone8Silverlight更新到Windows8.1RT(我想这就是所谓的)

我刚刚创建了第二个页面,当我转到并按下后退按钮时,它将退出我的应用程序,而不是返回第一个页面

我不知道为什么会发生这种情况,默认行为会一直持续到最后一页,对吗

我找不到如何重写back button事件以进行
Frame.GoBack()
调用


这是一个开发预览错误还是我遗漏了什么?

放入第二页的构造函数:(SecondPage.xaml.cs)

然后定义eventhandler函数:

    private void HardwareButtons_BackPressed( object sender, BackPressedEventArgs e )
    {
        Frame.GoBack();
        e.Handled = true;
    }

在通用Windows应用程序中,您还可以在App.xaml.cs文件中全局单击“后退按钮”。请参阅下文:

  • 在OnLaunched方法中,添加以下代码:

    protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
      //..Rest of code...
    
       rootFrame.Navigated += OnNavigated;
    
    
        // Register a handler for BackRequested events and set the
        // visibility of the Back button:
    
        SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
    
        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
            rootFrame.CanGoBack  ?
            AppViewBackButtonVisibility.Visible :
            AppViewBackButtonVisibility.Collapsed;
    
        //..Rest of code...
    
    }
    
  • 然后,应在App类中添加处理程序方法的代码:

        private void OnNavigated(object sender, NavigationEventArgs e)
        {
          // Each time a navigation event occurs, update the Back button's visibility:
    
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
            ((Frame)sender).CanGoBack ?
            AppViewBackButtonVisibility.Visible :
            AppViewBackButtonVisibility.Collapsed;
        }
    
    
    
       private void OnBackRequested(object sender, BackRequestedEventArgs e)
       {
          Frame rootFrame = Window.Current.Content as Frame;
    
          if (rootFrame.CanGoBack)
          {
            e.Handled = true;
            rootFrame.GoBack();
          }
       }
    

    通用应用程序不支持@igrali HardwareButtons类的可能重复项,仅支持Windows Phone 8。这个问题解决不了任何问题…你应该在说什么问题解决不了任何问题之前检查你的事实-这个链接说最低版本是Windows Phone 8.0。我的解决方案适用于通用应用程序,而你的问题仍然是重复的。好吧,我知道你可以从windows 8开始制作通用应用程序,我一直认为这是8.1版的新版本,不管怎样Visual Studio告诉我没有任何HardwareButtons类,有什么方法可以解决它?确保它在里面,如果windows PHONE应用程序会声明e.Handled=true;是否在“Frame.GoBack();”之后执行?查看windows 8.1软键的情况?如果页面未缓存并稍后重新创建,这不会造成泄漏吗?也许最好在进入时订阅,在退出时取消订阅?可能最好在
    App.xaml.cs
    中执行此操作,并首先选中
    Frame.CanGoBack
        private void OnNavigated(object sender, NavigationEventArgs e)
        {
          // Each time a navigation event occurs, update the Back button's visibility:
    
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
            ((Frame)sender).CanGoBack ?
            AppViewBackButtonVisibility.Visible :
            AppViewBackButtonVisibility.Collapsed;
        }
    
    
    
       private void OnBackRequested(object sender, BackRequestedEventArgs e)
       {
          Frame rootFrame = Window.Current.Content as Frame;
    
          if (rootFrame.CanGoBack)
          {
            e.Handled = true;
            rootFrame.GoBack();
          }
       }