使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页 [英] UWP Application launched with LaunchUriAsync is not showing main page

查看:20
本文介绍了使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have launched a uwp app with LaunchUriAsync but the application is not loading the properly(not showing main page of the application), it is showing default blue screen

 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 中添加以下代码

and in app.xaml.cs added the below code

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);

            }

        }

推荐答案

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

but the application is not loading the properly(not showing main page of the application), it is showing default blue screen

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

The problem is you have not invoke Window.Current.Activate(); method in OnActivated override function. Please use the following to replace yours.

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();
}

这篇关于使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆