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

Asked

Viewed 376 times

4

In previous versions it was possible to make such manipulation over writing 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 suitable method found to replace

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

2 answers

1

You are creating a universal project?

Try:

public static event EventHandler<BackPressedEventArgs> BackPressed

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;
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.