13

我正在通过以下方式填充跳转列表

    public static void AddToList(String path)
    {
        var jumpList = JumpList.GetJumpList(Application.Current);
        if (jumpList == null) return;

        string title = System.IO.Path.GetFileName(path);
        string programLocation = Assembly.GetCallingAssembly().Location;

        var jt = new JumpTask
        {
            ApplicationPath = programLocation,
            Arguments = path,
            Description = path,
            IconResourcePath = programLocation,
            Title = title
        };

        JumpList.AddToRecentCategory(jt);

        jumpList.Apply();
    }

效果很好。唯一的问题是我的应用程序中还有一个文件菜单,并且还想在那里显示最近的列表。我可以通过存储最近文件的第二个副本轻松做到这一点,但我想知道是否可以枚举跳转列表使用的文件列表。我一直无法弄清楚这样做的任何事情。

我在这里错过了什么吗?我可以枚举跳转列表中的文件,还是需要存储我自己的重复列表?

4

1 回答 1

2

我已经检查了你的代码。我对此有疑问。我查看了您提供的MSDN页面。在那里我看到了添加任务的例子:

private void AddTask(object sender, RoutedEventArgs e)
{
  //....
  //Mostly the same code as your
  JumpList jumpList1 = JumpList.GetJumpList(App.Current);
  jumpList1.JumpItems.Add(jumpTask1); // It is absent in your code!!!
  JumpList.AddToRecentCategory(jumpTask1);
  jumpList1.Apply();
}

我创建了两个自己的方法CreateExtract并且至少可以访问在当前会话任务期间创建的方法。这是我的代码:

private void Extract()
{
    var jumpList = JumpList.GetJumpList(Application.Current);

    if (jumpList == null) return;

    foreach (var item in jumpList.JumpItems)
    {
        if(item is JumpTask)
        {
            var jumpTask = (JumpTask)item;
            Debug.WriteLine(jumpTask.Title);
        }
    }
}
private void Create() {
    var jumpList = JumpList.GetJumpList(Application.Current);

    if (jumpList == null)
    {
        jumpList = new JumpList();
        JumpList.SetJumpList(Application.Current, jumpList);
    }

    string title = "Title";
    string programLocation = "Location";
    var path = "path";

    var jt = new JumpTask
    {
        ApplicationPath = programLocation,
        Arguments = path,
        Description = path,
        IconResourcePath = programLocation,
        Title = title
    };
    jumpList.JumpItems.Add(jt);
    JumpList.AddToRecentCategory(jt);
    jumpList.Apply();
}

我不确定这是否是您问题的答案,但我正在寻找您为什么不将任务添加到JumpItems列表的原因?

于 2016-09-09T11:40:09.003 回答