1

如何使用 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);
            }
        }
4

1 回答 1

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");
    }      
}

然后在 onlaunched 事件中,您可以通过创建一个新的 colloction 来读取路径,例如 mycoll 然后 var mycoll = colllaunch.coll; 之后,您可以从 mycoll[You specific TileID] 读取路径。

于 2018-07-20T07:24:31.943 回答