问题描述
限时送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:关键词]
发布评论