I am currently developing Windows Store application using C#. In my application i am using Secondary Tile option to pin one of my feature to the Start Screen using the following code.
if (SecondaryTile.Exists(TileId))
{
var secondaryTile = new SecondaryTile(TileId);
await econdaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Placement.Above);
}
else
{
var logo = new Uri("ms-appx:///Assets/A.png", UriKind.RelativeOrAbsolute);
var secondaryTile = new SecondaryTile
{
Logo = logo,
TileId = TileId,
ShortName = "AAAA",
Arguments = TileId + DateTime.Now.ToLocalTime(),
DisplayName = "AAAAAAA BBBBBBB",
TileOptions = TileOptions.ShowNameOnLogo,
ForegroundText = ForegroundText.Dark
};
await secondaryTile.RequestCreateForSelectionAsync(GetElementRect(sender as FrameworkElement), Placement.Above);
}
So it now hosts the SecondaryTile to the Start screen. But for my requirement whenever user click the SecondaryTile from the Start screen, It should navigate to the page "A". Can we achieve this in Windows Store apps ?
Yes but you should use another SecondaryTile constructor to pass some arguments along with the tile ID. You don't need to use another constructor because you can use only the Tile ID to decide what page your app must go when launched but I think it is better to use arguments to send the Page name or identification.
public SecondaryTile(
string tileId,
string shortName,
string displayName,
string arguments,
TileOptions tileOptions,
Uri logoReference
)
Documentation says that arguments is:
An app-defined string meaningful to the calling application. This argument string is passed back to the app when the app is activated from the secondary tile. It will be truncated after 2048 characters. Can be set or retrieved through the Arguments property
So you can pass a string that identifies the page that must be launched when the user clicks on the secondary tile and then use it on your App.xaml.cs OnLaunched method when the app is activated:
async protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var tile_id = args.TileId;
var tile_arguments = args.Arguments;
// Depending on tile_id and tile_arguments navigate to the page you want
}
Note that you should also be aware of args.PreviousExecutionState in OnLaunched method. Your OnLaunched method must not be just this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With