13

I'm populating a jumplist via:

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

Which works great. The only problem is that I also have a file menu in my application and would like to show the recent list there as well. I could do it easily by storing a second copy of the recent files, but I was wondering if I could possibly enumerate the list of files used by the jumplist. I haven't been able to figure out anything for doing so.

Am I missing something here? Can I enumerate the files in the jumplist, or do I need to store my own duplicate list?

Kyle
  • 16,103
  • 26
  • 123
  • 231
  • could you enumerate the list if it were declared outside of the AddToList() method perhaps create a static list ? – MethodMan Sep 15 '14 at 19:38
  • 3
    While you can use information from another control, it is usually preferable to have the shared data available in a view model that is independant of the UI so if at some point, you decide, you don't want the jump list anymore, then the list under the file menu won't be affected (and vice-versa). – Phil1970 Sep 07 '16 at 14:31

1 Answers1

2

I have checked your code. And I have the question to it. I looked into MSDN page that you provided. And there I see example of adding task:

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

I have created two my own methods Create and Extract and I can access to created during current session task at least. This is my code:

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

I am not sure that this is answer on your question, but I am looking to reason why you don't add your task to JumpItems list?

Kyle
  • 16,103
  • 26
  • 123
  • 231
RredCat
  • 4,775
  • 3
  • 54
  • 91