简体   繁体   中英

Secondary Tiles with Template 10

I am having a couple of issues with secondary tiles with Template 10.

The first is that I can't find the SecondaryTileService in the version that I am using (1.1.12) even though the source is in the GitHub repository and looks old. I have tried searching for a Template 10 Services nuget package but can't find one.

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

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.

In a non Template 10 app I can override the OnLaunched method in App.xaml.cs and use the TileId and Arguments properties of the LaunchActivatedEventArgs parameter to handle the navigation to the relevant view.

But the Template 10 BootStrapper seals the OnLaunched method and doesn't provide anything that obviously supplies the launch arguments.

The Template 10 services as seen in GitHub are not included in any Nuget package for reasons unknown.

Handling a launch from a secondary tile is quite an obscure process in Template 10.

First, in the OnStartAsync method, use the DetermineStartCause method of the Bootstrapper to get an AdditionalKinds enum value. If the value is AdditionalKinds.SecondaryTile then the app was launched from a secondary tile. You can then cast the IActivatedEventArgs parameter as a LaunchActivatedEventArgs , which contains the TileId and launch arguments.

Sample implementation:

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

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

I think you've done the right thing to use this SecondaryTileService , there are other services for example like LocationService , they are just not included into the Nuget package of Template 10.

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.

You may refer to the "The bootstrapper" part of this blog: Template10: a new template to create Universal Windows apps – The basics .

In the OnStartAsync() method you can handle the launch from a secondary tile.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM