使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页

编程入门 行业动态 更新时间:2024-10-28 16:17:25
本文介绍了使用 LaunchUriAsync 启动的 UWP 应用程序未显示主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 09:15:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1171568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   主页   LaunchUriAsync   UWP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!