在我的 Windows 应用商店应用程序中,我遵循 Microsoft 指南在应用程序终止后恢复应用程序(http://goo.gl/oZ7BG)。一切正常,但是在应用程序终止后,我想跳转登录页面(即应用程序的第一页)并直接转到应用程序的菜单页面。这绝对像 Dropbox 应用程序。我知道我必须使用 App.xaml.cs 和这个方法:
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
bool appTerminated = false;
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
marketingHP.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
await marketingHP.Common.SuspensionManager.RestoreAsync();
appTerminated = true;
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (appTerminated)
rootFrame.Navigate(typeof(HomePage), args.Arguments);
else if (!rootFrame.Navigate(typeof(LoginPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}
我怎么知道该应用程序之前已终止?请注意,我添加了 bool appTerminated 但它仅适用于挂起......