我发现您不能通过将数据传递到 Windows 8 应用程序的另一个页面来返回数据。您不能以传递数据的方式返回数据,即this.Frame.Navigate(typeof(MainPage), passData);
对于解决方案,我创建了一个“已完成”事件,并从后面的 MainPage C# 代码中调用它。
MainPage.xaml.cs:
protected override void OnNavigatedFrom(NavigationEventArgs args)
{
if (args.SourcePageType.Equals(typeof(ChildPage)))
(args.Content as ChildPage).Completed += OnChildPageCompleted;
base.OnNavigatedFrom(args);
}
void OnChildPageCompleted(object sender, ReturnData args)
{
// Code to run if returned back to MainPage from ChildPage
this.myNewString = returnData.myString;
(sender as ChildPage).Completed -= OnChildPageCompleted;
}
返回数据.cs:
namespace MyTestApp
{
class ReturnData
{
public String myString { set; get; }
}
}
ChildPage.xaml.cs:
public event EventHandler<ReturnData> Completed;
ChildPage.xaml.cs:
protected override void OnNavigatedFrom(NavigationEventArgs args)
{
if (Completed != null)
{
// Create ReturnData object
ReturnData returnData = new ReturnData();
returnData.myString = newStringChanged;
// Fire Completed event
Completed(this, returnData);
}
base.OnNavigatedFrom(args);
}