问题
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