c# - 如何固定seconadry瓷砖以打开文本文件?
问题描述
如何使用 App.xaml.cs 上的磁贴 ID、操作和激活来固定 Microsoft Edge 网站等辅助磁贴?我想在我的文本编辑器上固定打开的文本文件。
更新
这是我的 Pin 图代码:
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);
}
}
解决方案
当我们设置辅助磁贴时,我们将分配一个磁贴 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");
}
}
然后在 onlaunched 事件中,您可以通过创建一个新的 colloction 来读取路径,例如 mycoll 然后 var mycoll = colllaunch.coll; 之后,您可以从 mycoll[You specific TileID] 读取路径。
推荐阅读
- sql - Flink中如何通过SQL计算每分钟一天的uv
- gcc - 安装 OpenSMILE 2.3.0
- python - 如何为数据框创建循环?
- amazon-web-services - 为 sftp 传输保持 AWS Lambda 状态
- oauth - RFC6749 OAuth 2.0 可以有多个授权端点?
- javascript - 如何检查 ES6 静态方法是否存在
- image - 为什么这个 mdbootstrap 轮播代码会调整我的图像大小?
- python-3.x - 如何修复 Thycotic Secret Server 的 API 中的“SDK 客户端路径无效”错误
- java - 移动设备:Android:输入文本后如何按 Enter
- c# - 如何在运行时设置统一应用程序版本?