【问题标题】:UWP Application launched with LaunchUriAsync is not showing main page使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页
【发布时间】:2018-12-28 23:04:44
【问题描述】:

我使用 LaunchUriAsync 启动了一个 uwp 应用程序,但应用程序没有正确加载(不显示应用程序的主页),它显示默认蓝屏

 public MainPage()
        {
            this.InitializeComponent();
            callUri();


        }

        private async void callUri()
        {
            var uriBing = new Uri((@"testapptolaunch://"));

            // Launch the URI
            var success = await Windows.System.Launcher.LaunchUriAsync(uriBing);

        }

并在 app.xaml.cs 添加以下代码

protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
                // Navigate to a view 
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }
                // assuming you wanna go to MainPage when activated via protocol
                rootFrame.Navigate(typeof(MainPage), eventArgs);

            }

        }

【问题讨论】:

  • 嗨@Sruthi A,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您找到了解决方案,并为回答者和您自己赢得了一些声誉。

标签: uwp


【解决方案1】:

但应用程序没有正确加载(不显示应用程序的主页),它显示默认蓝屏

问题是你没有在OnActivated覆盖函数中调用Window.Current.Activate();方法。请使用以下内容替换您的。

protected override void OnActivated(IActivatedEventArgs args)
{

    if (args.Kind == ActivationKind.Protocol)
    {
        ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
        // Navigate to a view 
        Frame rootFrame = Window.Current.Content as Frame;
        if (rootFrame == null)
        {
            rootFrame = new Frame();
            Window.Current.Content = rootFrame;
        }
        // assuming you wanna go to MainPage when activated via protocol
        rootFrame.Navigate(typeof(MainPage), eventArgs);

    }
    Window.Current.Activate();
}

【讨论】:

    猜你喜欢
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多