How I can pin secondary tile like Microsoft Edge websites, with tile ID, action, and activaton on App.xaml.cs? I want to pin opened text file on my text editor.
Update
This is my code for Pin tile:
string tileId;
string path = ((StorageFile)currentEditBox.Tag).Path;
tileId = "file" + PivotMain.Items.Count;
TileCollection colllaunch = new TileCollection();
var mycoll = colllaunch.coll;
mycoll.Add(tileId, path);
// Use a display name you like
string displayName;
if(PivotMain.SelectedRichEditBoxItem.HeaderTextBlock.Text.Length > 10
&& currentEditBox.Tag != null)
{
displayName = ((StorageFile)currentEditBox.Tag).Name;
}
else
{
displayName = PivotMain.SelectedRichEditBoxItem.HeaderTextBlock.Text;
}
// Provide all the required info in arguments so that when user
// clicks your tile, you can navigate them to the correct content
string arguments = tileId;
var imageUri = new Uri("ms-appx:///Assets/Square150x150Logo.scale-100.png");
// During creation of secondary tile, an application may set additional arguments on the tile that will be passed in during activation.
// Create a Secondary tile with all the required arguments.
var secondaryTile = new SecondaryTile(tileId,
displayName,
arguments,
imageUri, TileSize.Default);
secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
await secondaryTile.RequestCreateAsync();
This is code for tile collection:
public class TileCollection
{
public Dictionary<string, string> coll = new Dictionary<string, string>();
}
And this is for OnNavigatedTo event (I can't call open file event, because it is is on MainPage.xaml, and I moved it on MainPage):
var launchArgs = e.Parameter as Windows.ApplicationModel.Activation.ILaunchActivatedEventArgs;
if(launchArgs != null)
{
TileCollection colllaunch = new TileCollection();
var mycoll = colllaunch.coll;
if (launchArgs.TileId != "App")
{
StorageFile storageFile;
string path;
mycoll.TryGetValue(launchArgs.TileId, out path);
storageFile = await StorageFile.GetFileFromPathAsync(path);
await OpenFile(storageFile);
}
}
When we set our secondary tile we will assign a tile ID like the following code:
Then in the Onlaunched event we will be able to detect the tileID by the following code:
There is a document on Technet wiki about how you can specify the content by ID.
------Update-----
For how to create a Dictionary and read it, here I just assume that you will not have a huge list, so a simple demo code:
Then in onlaunched event you can read the path by create a new colloction like mycoll and then var mycoll = colllaunch.coll; after that you can read the path from mycoll[You specific TileID].