使用OnNavigatedFrom方法当我们调用NavigationService.Navigate方法
OnNavigateFrom被调用。它具有一个NavigationEventArgs对象作为参数,返回目标页面的Content属性,我们可以通过该属性访问目标页面的属性“DestinationPage.xaml.cs”
首先,在目标页面“DestinationPage.xaml。 CS “申报财产 ”SomeProperty“:
public ComplexObject SomeProperty { get; set; }
现在,在 ”MainPage.xaml.cs中“,覆盖OnNavigatedFrom方法:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// NavigationEventArgs returns destination page "DestinationPage"
DestinationPage dPage = e.Content as DestinationPage;
if (dPage != null)
{
// Change property of destination page
dPage.SomeProperty = new ComplexObject();
}
}
现在,拿在SomeProperty值” DestinationPage。 xaml.cs“:
private void DestinationPage_Loaded(object sender, RoutedEventArgs e)
{
// This will display a the Name of you object (assuming it has a Name property)
MessageBox.Show(this.SomeProperty.Name);
}
谢谢。默认项目通过查询字符串间接传递对象,查询字符串然后从App.ViewModel访问。这将工作,但我希望有一个更直接传递对象的更优雅的解决方案。 – samwize 2010-11-30 03:08:14