Methods for passing parameters
1. Using the query string
You can pass parameters through the query string using this method, which means you need to convert your data into strings and encode their URLs. You should only use this to transmit simple data.
Page navigation:
page.NavigationService.Navigate(new Uri("/Views/Page.xaml?parameter=test", UriKind.Relative));
Destination Page:
string parameter = string.Empty; if (NavigationContext.QueryString.TryGetValue("parameter", out parameter)) { this.label.Text = parameter; }
2. Using NavigationEventArgs
Page navigation:
page.NavigationService.Navigate(new Uri("/Views/Page.xaml?parameter=test", UriKind.Relative)); // and .. protected override void OnNavigatedFrom(NavigationEventArgs e) { // NavigationEventArgs returns destination page Page destinationPage = e.Content as Page; if (destinationPage != null) { // Change property of destination page destinationPage.PublicProperty = "String or object.."; } }
Destination Page:
// Just use the value of "PublicProperty"..
3. Using manual navigation
Page navigation:
page.NavigationService.Navigate(new Page("passing a string to the constructor"));
Destination Page:
public Page(string value) {
The difference between Uri and manual navigation
I think the main difference here is the application life cycle. Manually created pages are stored in memory for navigation purposes. Read more about it here .
Complex Object Transfer
You can use one or two methods to transfer complex objects (recommended). You can also add custom properties to the Application class or save data to Application.Current.Properties .
Daniel Little Sep 16 '12 at 6:17 2012-09-16 06:17
source share