【问题标题】:Enumerate JumpList recent files?枚举 JumpList 最近的文件?
【发布时间】:2014-11-09 10:06:25
【问题描述】:

我正在通过以下方式填充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();
    }

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

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

【问题讨论】:

  • 如果列表是在 AddToList() 方法之外声明的,您能否枚举列表,或者创建一个静态列表?
  • 虽然您可以使用来自另一个控件的信息,但通常最好在独立于 UI 的视图模型中提供共享数据,因此如果在某个时候您决定,您不不再需要跳转列表,则文件菜单下的列表不会受到影响(反之亦然)。

标签: c# wpf jump-list


【解决方案1】:

我已经检查了您的代码。我对此有疑问。我查看了您提供的 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 列表的原因?

【讨论】:

    猜你喜欢
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多