带有模板 10 的辅助磁贴

Secondary Tiles with Template 10

我在使用模板 10 的辅助磁贴方面遇到了一些问题。

首先是我无法在我使用的版本 (1.1.12) 中找到 SecondaryTileService,即使源代码在 GitHub 存储库中并且看起来很旧。我曾尝试搜索模板 10 服务 nuget 包,但找不到。

为了使用辅助磁贴服务,我已将源代码复制到我的应用程序中..

我遇到的第二个问题是如何处理从辅助磁贴启动。我似乎找不到任何关于此的文档。

在非 Template 10 应用程序中,我可以覆盖 App.xaml.cs 中的 OnLaunched 方法,并使用 LaunchActivatedEventArgs 参数的 TileId 和 Arguments 属性来处理相关视图的导航。

但是 Template 10 BootStrapper 密封了 OnLaunched 方法并且没有提供任何明显提供启动参数的内容。

In order to use the secondary tile service I have copied the source code to my application..

我认为您使用此 SecondaryTileService 的做法是正确的,还有其他服务,例如 LocationService,它们只是未包含在模板 10 的 Nuget 包中。

The second issue I am having is how to handle the launch from a secondary tile. There doesn't seem to be any documentation on this that I can find.

您可以参考此博客的 "The bootstrapper" 部分:Template10: a new template to create Universal Windows apps – The basics

OnStartAsync() 方法中,您可以处理从辅助磁贴启动。

The core is the OnStartAsync() method, which is the starting point of the application, regardless from the activation’s scenario. No matter if the app has been opened using the main tile, a secondary tile or from a toast notification, the OnStartAsync() method will always be invoked to let you, as developer, handling the main navigation.

GitHub 中看到的模板 10 服务未包含在任何 Nuget 包中,原因不明。

处理从辅助磁贴的启动在模板 10 中是一个相当晦涩的过程。

首先,在OnStartAsync方法中,使用BootstrapperDetermineStartCause方法得到一个AdditionalKinds枚举值。如果值为 AdditionalKinds.SecondaryTile,则应用程序是从辅助磁贴启动的。然后,您可以将 IActivatedEventArgs 参数转换为 LaunchActivatedEventArgs,其中包含 TileId 和启动参数。

实施示例:

public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
    AdditionalKinds cause = DetermineStartCause(args);
    if (cause == AdditionalKinds.SecondaryTile)
    {
        LaunchActivatedEventArgs eventArgs = args as LaunchActivatedEventArgs;
        NavigationService.Navigate(typeof (DetailPage), eventArgs.Arguments);
    }
    else
    {
        NavigationService.Navigate(typeof (MainPage));
    }

    return Task.FromResult<object>(null);
}