Refresh Or Update Page on click of back button (WP

2019-09-05 14:26发布

问题:

I have used the standard navigation service in my app but the problem is

Accounts Page (Show info from datacontext) -> Add Accounts Page

now if i give navigation to Accounts Page from Add Accounts Page it creates new instance of Accounts Page as below

Accounts Page (Old Data) -> Add Accounts Page -> Accounts Page (Updated Data)

when i get to the new instance the data on the page shows the new entry but if get back i get to the add accounts page again & then Accounts Page (Old Data) which does not show the updated entryso i have to get back to the home pag & again navigate to Accounts Page to get it updated so what should i do to make Add Accounts Page save button send me back to the Accounts Page & its updated?

I tried with

NavigationService.GoBack();

NavigationService.RemoveBackEntry();

NavigationService.Navigate(new Uri(string.Format("/Accounts.xaml?Refresh=true"), UriKind.Relative));

but nothing worked as i wanted PLEASE HELP

回答1:

NavigationService.GoBack(); is the right way. The problem you need to focus on is: "how to refresh the data when going back to the Accounts Page". The solution depends on your application's architecture. If you used the MVVM pattern, then it's just a matter of adding the new account to the data source in the viewmodel. Otherwise, you should probably reload the account list in the OnNavigatedTo method of your page:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    // Load the accounts
}