UWP Application launched with LaunchUriAsync is not showing main page

徘徊边缘 提交于 2020-01-05 04:28:28

问题


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

        }

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

            }

        }

回答1:


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

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


来源:https://stackoverflow.com/questions/51445858/uwp-application-launched-with-launchuriasync-is-not-showing-main-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!