How to handle the event generated by the Windows Phone 8.1 back button?

4

In previous versions it was possible to do such manipulation overwriting the OnBackKeyPress.

 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {            
        .
        .
        .
    }

However, two errors are presented:

  

.OnBackKeyPress (System.ComponentModel.CancelEventArgs) 'is a new
     virtual member in sealed class

     

.OnBackKeyPress (System.ComponentModel.CancelEventArgs) 'none      Appropriate method found to replace

How to do the same in the new version of Windows Phone?

    
asked by anonymous 01.08.2014 / 23:59

2 answers

1

Are you creating a universal project?

Try:

public static event EventHandler<BackPressedEventArgs> BackPressed
    
04.08.2014 / 15:48
1

try setting the BackPressedEventArgs.Handled property to true.

private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {
        Frame frame = Window.Current.Content as Frame;
        if (frame == null)
        {
            return;
        }

        if (frame.CanGoBack)
        {
            frame.GoBack();
            e.Handled = true;
        }
    }
    
08.08.2014 / 16:42