简体   繁体   中英

Handling the back button with parameter in windows phone 8.1

I create one page Windows Phone 8.1 Universal App. i want when click on button navigate back to page came from.

    private void backbtn_Click(object sender, RoutedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame != null && rootFrame.CanGoBack)
        {                
            rootFrame.GoBack();
        }
    }

the problem is, i want back some parameter like id=10&name=test

i can do it when navigate to Uri

Frame.Navigate(typeof(page1), "id=1");

or

await Windows.System.Launcher.LaunchUriAsync(new Uri("myapp:///id=1"));

but there is no function to do it

        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame != null && rootFrame.CanGoBack)
        {                
            rootFrame.GoBack("some parameter id=10");
        }

thanks

It was a problem for me as well, so I in such a scenario I came up with the idea to create a static class where I put my data which I need to pass back. On the page which you navigate from, you can write the data in OnNavigatedFrom, and then on the page where you navigate to, you can read that data in the OnNavigatedTo method, if the NavigationMode is NavigationMode.Back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM