翻译自:http://stackoverflow.com/questions/12444816/how-to-pass-values-parameters-between-xaml-pages
Xaml两个页面间的传值方式:
1. 用query字符串
导航页:
page.NavigationService.Navigate(new Uri("/Views/Page.xaml?parameter=test", UriKind.Relative));
目标页使用参数:
String parameter = string.Empty;if(NavigationContext.QueryString.TryGetValue("parameter", out parameter)) { this.label.Text = parameter;}
2. 使用NavigationEventArgs
导航页:
page.NavigationService.Navigate(new Uri("/Views/Page.xaml?parameter=test",UriKind.Relative));
// and ..
protectedoverride 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.."; }}
目标页直接使用PublicProperty 的值:
// Just use the value of "PublicProperty"..
3. 使用构造时传递
导航页:
page.NavigationService.Navigate(newPage("passing a string to the constructor"));
目标页:
public Page(string value) { // Use the value in the constructor...}
Catold.晖
13/11/18