如何在启动屏幕加载之后以及网格模板应用程序加载C#XMAL Windows 8商店应用程序之前导航到页面?

时间:2014-11-22 10:55:59

标签: c# windows-store-apps windows-8.1

这是我第一次使用stackoverflow :),

我正在使用Windows 8商店应用中的网格模板应用,我想在加载启动画面后添加欢迎页面,为此我尝试添加此声明

this.Frame.Navigate(typeof(WelcomePage)); 

默认情况下使用OnLaunched中的网格模板创建的App.xmal.cs方法。在我创建了Welcomepage之后,我在欢迎页面中创建了一个按钮,以导航到GroupedItemsPage

我的逻辑不起作用。

这是App.xmal.cs中的默认方法代码,如果有帮助的话

 protected override async 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

    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();
        //Associate the frame with a SuspensionManager key                                
        SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

        if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            // Restore the saved session state only when appropriate
            try
            {
                await SuspensionManager.RestoreAsync();
            }
            catch (SuspensionManagerException)
            {
                //Something went wrong restoring state.
                //Assume there is no state and continue
            }
        }

        // 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 (!rootFrame.Navigate(typeof(GroupedItemsPage), "AllGroups"))
        {
            throw new Exception("Failed to create initial page");
        }
    }
    // Ensure the current window is active
    Window.Current.Activate();
}

0 个答案:

没有答案