我如何在App.xaml.cs上将诸如Microsoft Edge网站之类的辅助图块与图块ID,操作和激活固定在一起?我想将打开的文本文件固定在文本编辑器上。
更新
这是我的图钉拼贴代码:
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();
这是用于图块收集的代码:
public class TileCollection
{
public Dictionary<string, string> coll = new Dictionary<string, string>();
}
这是针对OnNavigatedTo事件的(我无法调用打开文件事件,因为它位于MainPage.xaml上,并且将其移至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);
}
}
答案 0 :(得分:0)
设置辅助图块时,我们将分配一个图块ID,如以下代码所示:
var secondaryTile = new SecondaryTile(“tile ID”,
"App Name",
"args",
"tile",
options,
imageUri)
{ RoamingEnabled = true };
await secondaryTile.RequestCreateAsync();
然后在Onlaunched事件中,我们将能够通过以下代码检测tileID:
CollInit colllaunch = new CollInit();
var mycoll = colllaunch.coll;
if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (e.TileId == "xxxxxx")
{
//Do what you want to do here
var filepath=mycoll[xxxxxx];
//Then navigate to a specific page
rootFrame.Navigate(typeof(AlternatePage));
}
else
{
rootFrame.Navigate(typeof(MainPage), e.TileId);
}
}
// Ensure the current window is active
Window.Current.Activate();
}
Technet wiki上有一个文档,说明如何通过ID指定内容。
------更新-----
关于如何创建字典并阅读它,在这里我只是假设您将没有一个庞大的列表,因此有一个简单的演示代码:
public class CollInit
{
public Dictionary<string, string> coll = new Dictionary<string, string>();
public CollInit()
{
coll.Add("1233", "path1");
coll.Add("1234", "path2");
coll.Add("1235", "path3");
}
}
然后,在启动事件中,您可以通过创建新的集合(例如mycoll)然后var mycoll = colllaunch.coll;来读取路径。之后,您可以从mycoll [您特定的TileID]中读取路径。