你可以用Application.Current.Properties在整个程序范围内保存一些值,就像ASP.NET的Session对象一样。
public partial class TaskPage : Page
{
...
void okButton_Click(object sender, RoutedEventArgs e)
{
// Accept task when Ok button is clicked
TaskPageReturn(true);
}
void cancelButton_Click(object sender, RoutedEventArgs e)
{
// Cancel task
TaskPageReturn(false);
}
void TaskPageReturn(bool taskResult)
{
Application.Current.Properties["TaskResult"] = taskResult;
// Return to calling page
this.NavigationService.GoBack();
}
}
...
public partial class CallingPage : Page
{
...
void callingPage_Loaded(object sender, RoutedEventArgs e)
{
// If a task happened, get task result
if (Application.Current.Properties["TaskResult"] == null) return;
bool taskResult = (bool)Application.Current.Properties["TaskResult"];
// Remove result and data
Application.Current.Properties["TaskResult"] = null;
}
...
}