Handling Back Navigation Windows 10 (UWP)

前端 未结 5 706
礼貌的吻别
礼貌的吻别 2020-11-30 10:32

In my Xaml Page I\'ve got a Frame.

I\'m trying to have a backButton event to just navigate inside frame .

so I tried to use this piece of code



        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 10:54

    follow these steps:

    • Add two Global Variables in your page as below.

      private NavigationHelper navigationHelper;
      private RelayCommand _GoBackCommand;
      
    • Then add below code in constructor of specific page.

          // below code is to override the back navigation
          // hardware back button press event from navigationHelper
          _GoBackCommand = new RelayCommand
              (
                  () => this.CheckGoBack(),
                  () => this.CanCheckGoBack()
              );
      
          navigationHelper.GoBackCommand = _GoBackCommand;
          // ---------
      
    • Then add both those methods we've just declared in constructor.

      private bool CanCheckGoBack()
      {
          // this should be always true to make sure the app handles back buton manually.
          return true;
      }
      
      private void CheckGoBack()
      {
          // this will be execute when back button will be pressed
      }
      

    ps. - for this you might need to use BasicPage instead of BlankPage while adding new page.

    hope this will help..!

提交回复
热议问题