我在使用WPF中的JumpList时遇到了一些问题。当我在app.xaml中添加标签后,可以在跳转列表中看到任务,但是当我尝试向最近文件列表中添加项目时,新添加的项目从未出现。如果我创建一个名为“最近”的CustomCategory并手动添加JumpTask,则该任务将显示出来。但是,如果我重新启动应用程序,则新添加的JumpTask不再存在,只有测试任务。
澄清
最初,我遇到了JumpList.AddToRecentCategory根本无法工作的问题。它永远不会添加到最近列表中。Gayot Fow帮助解决了这个问题。但是问题仍然存在,即如果我手动使用自定义类别添加JumpTask,则所有最近的文件都会清除,如果我打开一个文件并调用addToRecent,则不会显示该文件。如果我删除在xaml中声明的JumpTask,则最近的文件将显示出来。
XAML:
无论我是从Visual Studio 2013(更新2)运行应用程序,还是从调试目录运行exe,这种情况都会发生。有人有任何想法为什么这不起作用吗?
我在某个地方读到过ClickOnce部署的应用程序不起作用,但我甚至不能在部署之前使其工作。
任何帮助将不胜感激,谢谢。
更新
Gayot Fow的答案让我解决了静态方法的问题。
一旦调用此函数,最近类别将消失,任何添加最近项的调用都不会起作用。然而,我仍然看到我的“新建文档”任务 :/ 我是不是完全错了呢? 谢谢
XAML:
<JumpList.JumpList>
<JumpList ShowRecentCategory="True">
<JumpTask Title="Test" Description="Test"
Arguments="/test" CustomCategory="Tasks" />
</JumpList>
</JumpList.JumpList>
添加最近项目的C#代码
var jumpList = JumpList.GetJumpList(Application.Current);
if (jumpList == null) return;
//create a jump task
var jt = new JumpTask();
jt.Title = System.IO.Path.GetFileNameWithoutExtension(FileName);
jt.Description = jt.Title;
jt.CustomCategory = jt.Title;
jt.ApplicationPath = FileName;
//JumpList.AddToRecentCategory(jt);
jt.CustomCategory = "Recent";
jumpList.JumpItems.Add(jt);
jumpList.Apply();
无论我是从Visual Studio 2013(更新2)运行应用程序,还是从调试目录运行exe,这种情况都会发生。有人有任何想法为什么这不起作用吗?
我在某个地方读到过ClickOnce部署的应用程序不起作用,但我甚至不能在部署之前使其工作。
任何帮助将不胜感激,谢谢。
更新
Gayot Fow的答案让我解决了静态方法的问题。
JumpList.AddToRecentCategory(jt);
没有做任何事情。
我已经将我的AddToRecent代码更改如下:
var jumpList = JumpList.GetJumpList(Application.Current);
if (jumpList == null) return;
string title = System.IO.Path.GetFileNameWithoutExtension(FileName);
string programLocation = Assembly.GetCallingAssembly().Location;
var jt = new JumpTask
{
ApplicationPath = programLocation,
Arguments = FileName,
Description = FileName,
IconResourcePath = programLocation,
Title = title
};
JumpList.AddToRecentCategory(jt);
jumpList.Apply();
问题
虽然最近文件的问题已经解决,但我仍然无法让它与名为“任务”的自定义类别共存。
在我的应用程序启动时,我调用以下代码:
var jumpList = JumpList.GetJumpList(Application.Current);
if (jumpList != null)
{
string title = "New Document";
string programLocation = Assembly.GetCallingAssembly().Location;
var jt = new JumpTask
{
ApplicationPath = programLocation,
Arguments = "/new",
Description = title,
IconResourcePath = programLocation,
Title = title
};
jumpList.JumpItems.Add(jt);
jumpList.Apply();
}
一旦调用此函数,最近类别将消失,任何添加最近项的调用都不会起作用。然而,我仍然看到我的“新建文档”任务 :/ 我是不是完全错了呢? 谢谢