gpt4 book ai didi

c# - 枚举 JumpList 最近的文件?

转载 作者:可可西里 更新时间:2023-11-01 08:13:00 26 4
gpt4 key购买 nike

我正在填充 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();
}

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

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

最佳答案

我检查了你的代码。我对此有疑问。我调查了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 并且我至少可以访问在当前 session 任务期间创建的。这是我的代码:

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 的原因。名单?

关于c# - 枚举 JumpList 最近的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25855525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com