private string tag;
//If the app navigates to the MainPage.Xaml this function tries to read a a tag-property from the Uri.
//You use the Uri to navigate between pages by calling the NavigationServices.Navigate(new Uri("/MainPage.xaml",UriKind.Relative)).
//To push a parameter to the site you can add them to the uri as following:
//"/MainPage.xaml?tag=tagnvalue&otherproperty=othervalue"
//If you launch the app these settings are empty
//If you launch it with the pinned tile you can set this Uri to submit the parameters
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
//get the value.
NavigationContext.QueryString.TryGetValue("tag", out tag);
//restart, shutdown... depending on the tagvalue. if tag is empty nothing happens (you can add a case default: "your code" break; to perform a default action)
switch(tag)
{
case "soft":
softreset(); //your void to perform the softreset
break;
case "hard":
hardreset();
break;
case "shotdown"
shotdown();
break;
}
}
//the functions performing the different restart modes
private void softreset()
{
}
private void hardreset()
{
}
private void shutdown()
{
}
//this action creates a softreset tile by calling PinToStart("soft");
private void PinToStart(string tag)
{
string title = "";
//set the title of the tile
switch (tag)
{
case "soft":
title = "soft reset";
break;
case "hard":
title = "hard reset";
break;
case "shotdown"
title = "shutdown";
break;
}
//search the tile with the title given by the tag in the step before
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=" + tag));
//if it's not existing this creates a new one
if (TileToFind == null)
{
//the data for the tile
StandardTileData NewTileData = new StandardTileData
{
//you can create different images for the tiles called "softTile.jpg", "hardTile.jpg", etc. in you "Images" folder
BackgroundImage = new Uri("Images/" + tag + "Tile.jpg", UriKind.Relative),
Title = title,
//Count = 12,
//BackTitle = "",
//BackContent = "",
//BackBackgroundImage = new Uri("Blue.jpg", UriKind.Relative)
};
//create a new tile with the tiledata
ShellTile.Create(new Uri("/MainPage.xaml?tag=" + tag, UriKind.Relative), NewTileData);
}