Passing data from page to page

2019-01-03 02:17发布

I'm looking for the best practice on how to pass data from page to page.

In Page A I have a button that fires off Page B.
On Page B I have 6 textboxes that allow the user to enter information. When the user is done, the click on a button that brings them back to Page A.

I want to pass that data back to Page A.

I've seen suggestions to:

  • build XML documents and save to Isolated Storage
  • use the App class to store information in properties
  • pass it like a query string

I'm looking for the Best practice. Is there one that Microsoft recommends or one that is generally accepted as the best way?

Thanks

8条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-03 03:17

as i implemented like this.. Whether its correct or not i dont know..

When u click news list page it should open the news detail page. I want to pass the selected news item contents from news List-Page to news-details Page.

the News list page contains following method.

 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        NewsDetailsPage newsDetailPage = (e.Content as NewsDetailsPage);
        if (newsDetailPage != null)
            newsDetailPage.SelectedNewsItem = SelectedNewsItem; //Contains the news details
        base.OnNavigatedFrom(e);
    }

In the News details Page. U can access that(SelectedNewsItem) object.

This may or may not be correct.

查看更多
闹够了就滚
3楼-- · 2019-01-03 03:18

Personally I'd store the values entered on Page B in a model(object) that is also accessible to Page A.

Depending on how you're navigating to Page A the second time, one or more of the following may be usful to help understand passing values between pages:

How to pass the image value in one xaml page to another xaml page in windows phone 7?

Passing a complex object to a page while navigating in a WP7 Silverlight application

How to pass an object from a xaml page to another?

How to pass a value between Silverlight pages for WP7?

How do I navigate from one xaml page to another, and pass values?

查看更多
登录 后发表回答