根据 Microsoft Docs,您可以使用此代码处理应用程序 uri
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
}
}
但那是从默认模板创建应用程序的时候。我的 UWP 项目是使用 Windows Template Studio 创建的,目前,我想将代码放入的位置现在是
protected override async void OnActivated(IActivatedEventArgs args)
{
await ActivationService.ActivateAsync(args);
}
这导致了这个..
public async Task ActivateAsync(object activationArgs)
{
if (IsInteractive(activationArgs))
{
// Initialize things like registering background task before the app is loaded
await InitializeAsync();
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (Window.Current.Content == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
Window.Current.Content = _shell;
NavigationService.Frame.NavigationFailed += (sender, e) =>
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
};
NavigationService.Frame.Navigated += OnFrameNavigated;
if (SystemNavigationManager.GetForCurrentView() != null)
{
SystemNavigationManager.GetForCurrentView().BackRequested += OnAppViewBackButtonRequested;
}
}
}
var activationHandler = GetActivationHandlers().FirstOrDefault(h => h.CanHandle(activationArgs);
if (activationHandler != null)
{
await activationHandler.HandleAsync(activationArgs);
}
if (IsInteractive(activationArgs))
{
var defaultHandler = new DefaultLaunchActivationHandler(_defaultNavItem);
if (defaultHandler.CanHandle(activationArgs))
{
await defaultHandler.HandleAsync(activationArgs);
}
// Ensure the current window is active
Window.Current.Activate();
// Tasks after activation
await StartupAsync();
}
}
请,如果有人以前使用过 Windows Template Studio。请告诉我如何在这段代码中处理 Uri。我不知道把它放在哪里。目前,我的应用程序从 Uri 启动时启动到空白页面