Windows 8.1 BackPressed phone not working properly

Windows phone 8.1 is new to the world. The main function is clicking on the button. This function does not work properly, it is a Windows 8.1 phone. This behavior or I'm wrong.

The code below is used on the home page, but this code also calls from another class when clicked. I need to use the method below only on the home page.

Please check the code below and return me a good solution.

Check out my code:

 public HomePage()
 {
  this.InitializeComponent(); 
  Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
 }

    void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {

    }

thank

+4
source share
1 answer

It is working correctly. The BackPressed event works in the application. Two options come to me:

  • , , , - :

    private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
    {
        Frame frame = Window.Current.Content as Frame;
        if (frame == null) return;
    
        if (frame.Content is HomePage)
        {
            e.Handled = true;
            Debug.WriteLine("I'm in HomePage");
        }
        else if (frame.CanGoBack)
        {
            frame.GoBack();
            e.Handled = true;
        }
    }
    
  • - Windows.Phone.UI.Input.HardwareButtons.BackPressed . , - OnNavigatedTo, OnNavigatedFrom, Suspending Resuming ( Lifecycle ). , - , NavigationHelper.

- , :

  • - BackPressed ( App.xaml.cs) - , ,
  • , NavigationHelper - BackPressed
  • ,
+10

Source: https://habr.com/ru/post/1546023/


All Articles