枚举JumpList最近的文件?

时间:2014-09-15 19:29:54

标签: c# wpf jump-list

我通过以下方式填充jumplist

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

哪个效果很好。唯一的问题是我的应用程序中还有一个文件菜单,并希望在那里显示最近的列表。我可以通过存储最近文件的第二个副本来轻松完成,但我想知道是否可以枚举跳转列表使用的文件列表。我无法弄明白这样做。

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

1 个答案:

答案 0 :(得分: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列表?