【问题标题】:Set startup form for Store App为 Store App 设置启动表单
【发布时间】:2014-05-14 17:12:18
【问题描述】:

我在 Visual Studio 2013 中制作了一个 C# 商店应用程序。突然间,启动形式发生了变化,因此不再是主页。我找不到如何解决这个问题。
我找到了a link,我可以在我的项目属性中做一些事情,但我无法解决问题。

有人知道如何在 Visual Studio 2013 中更改 C# 商店应用的启动表单吗?

编辑:这里是 cmets 中的 OnLaunched 方法。

        protected override async void OnLaunched(LaunchActivatedEventArgs e)
    {

#if DEBUG
        if (System.Diagnostics.Debugger.IsAttached)
        {
            this.DebugSettings.EnableFrameRateCounter = true;
        }
#endif

        Frame rootFrame = Window.Current.Content as Frame;

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            await CatalogApp.Common.SuspensionManager.RestoreAsync();
        }
        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();
            CatalogApp.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame");
            // Set the default language
            rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

            rootFrame.NavigationFailed += OnNavigationFailed;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
            }

            // Place the frame in the current Window+
            Window.Current.Content = rootFrame;
        }

        if (rootFrame.Content == null)
        {
            if (!rootFrame.Navigate(typeof(ShowItems), e.Arguments))
            {
                throw new Exception("Failed to create initial page");
            }

            rootFrame.Navigate(typeof(MainPage), e.Arguments);
        }
        Window.Current.Activate();
    }

【问题讨论】:

    标签: c# windows-store-apps


    【解决方案1】:

    中可能有这样的导航语句:rootFrame.Navigate(typeof(ItemsPage), e.Arguments);
    protected override async void OnLaunched(LaunchActivatedEventArgs e)
    

    在 App.xaml.cs 中覆盖

    如果您使用此默认值,请检查 typeof(ItemsPage)e.Argument 语句。

    请记住,默认情况下,在激活时, 应用程序重定向到最后打开的窗口。

    更新

    if (!rootFrame.Navigate(typeof(ShowItems), e.Arguments))
    {
        throw new Exception("Failed to create initial page");
    }
    
    rootFrame.Navigate(typeof(MainPage), e.Arguments);
    

    是双重导航:首先导航到ShowItems,如果成功导航到MainPage。这是为什么?我认为这会导致意想不到的结果。

    请尝试删除

    if (!rootFrame.Navigate(typeof(ShowItems), e.Arguments))
    {
        throw new Exception("Failed to create initial page");
    }
    

    并检查结果。

    顺便问一下:你想从哪一页开始?

    【讨论】:

    • 让我编辑页面,以便您可以看到该方法。我不知道哪里出了问题。
    • 如您所见,确实有一个 rootframe.navigate(typeof(MainPage), e arguments);现在我可以检查什么,然后它应该显示 MainPage? (它没有)
    • @Proliges:您是否要测试ShowItems 页面?那你应该用另一种方式吗?去掉测试线后还能用吗?
    • 我想从 MainPage 开始。现在它从 ShowItems 开始。注意:这突然发生了,回家,回来,没有主页启动:)
    • 哦,当我删除那段代码时,它不会再启动了。只有启动画面,然后全黑。
    猜你喜欢
    • 2014-11-14
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多