private async void PinButton_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
if (button != null)
{
// Prepare package images for our tile to be pinned
Uri square70x70Logo = new Uri("ms-appx:///Assets/square70x70Tile-sdk.png");
Uri square150x150Logo = new Uri("ms-appx:///Assets/square150x150Tile-sdk.png");
Uri wide310x150Logo = new Uri("ms-appx:///Assets/wide310x150Tile-sdk.png");
Uri square310x310Logo = new Uri("ms-appx:///Assets/square310x310Tile-sdk.png");
Uri square30x30Logo = new Uri("ms-appx:///Assets/square30x30Tile-sdk.png");
// During creation of the secondary tile, an application may set additional arguments on the tile that will be passed in during activation.
// These arguments should be meaningful to the application. In this sample, we'll pass in the date and time the secondary tile was pinned.
string tileActivationArguments = MainPage.logoSecondaryTileId + " WasPinnedAt=" + DateTime.Now.ToLocalTime().ToString();
// Create a Secondary tile with all the required arguments.
SecondaryTile secondaryTile = new SecondaryTile(MainPage.logoSecondaryTileId,
"Title text shown on the tile",
tileActivationArguments,
square150x150Logo,
TileSize.Square150x150);
// Only support of the small and medium tile sizes is mandatory.
// To have the larger tile sizes available the assets must be provided.
secondaryTile.VisualElements.Wide310x150Logo = wide310x150Logo;
secondaryTile.VisualElements.Square310x310Logo = square310x310Logo;
// If the asset for the small tile size is not provided, it will be created by scaling down the medium tile size asset.
// Thus, providing the asset for the small tile size is not mandatory, though is recommended to avoid scaling artifacts and can be overridden as shown below.
// Note that the asset for the small tile size must be explicitly provided if alternates for the small tile size are also explicitly provided.
secondaryTile.VisualElements.Square70x70Logo = square70x70Logo;
// Like the background color, the square30x30 logo is inherited from the parent application tile by default.
// Let's override it, just to see how that's done.
secondaryTile.VisualElements.Square30x30Logo = square30x30Logo;
// The display of the secondary tile name can be controlled for each tile size.
// The default is false.
secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = false;
secondaryTile.VisualElements.ShowNameOnWide310x150Logo = true;
secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = true;
// Add the handler for the VisualElemets request.
// This is needed to add alternate tile options for a user to choose from for the supported tile sizes.
secondaryTile.VisualElementsRequested += VisualElementsRequestedHandler;
// Specify a foreground text value.
// The tile background color is inherited from the parent unless a separate value is specified.
secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;
// Set this to false if roaming doesn't make sense for the secondary tile.
// The default is true;
secondaryTile.RoamingEnabled = false;
// OK, the tile is created and we can now attempt to pin the tile.
// Note that the status message is updated when the async operation to pin the tile completes.
bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(MainPage.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);
if (isPinned)
{
rootPage.NotifyUser("Secondary tile successfully pinned.", NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("Secondary tile not pinned.", NotifyType.ErrorMessage);
}
}
}