I'm having some trouble with WPF's . When I add the tag to my app.xaml, I can see the task in the jump list, but when I try to add an item to the recent files list, the new item I add never shows up. If I create a CustomCategory called "Recent" and manually add a JumpTask, it shows up. However, if I restart the app, the newly added JumpTask is no longer there, just the test task.
clarification
Originally, I had issues with JumpList.AddToRecentCategory not working at all. It would never add to the recent list. Gayot Fow helped solved that. But the issue still exists that if I manually add a JumpTask with a custom category, then all of the recent files clear out, and if I open a file and call addToRecent, it does not show up. If i remove the JumpTask declared in xaml, then the recent files show up.
XAML:
<JumpList.JumpList>
<JumpList ShowRecentCategory="True">
<JumpTask Title="Test" Description="Test"
Arguments="/test" CustomCategory="Tasks" />
</JumpList>
</JumpList.JumpList>
C# code to add recent item
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();
This occurs whether I run the app from Visual Studio 2013 (update 2), or run the exe from the debug directory. Does anyone have any ideas why this isn't working?
I read somewhere about ClickOnce deployed apps not working, but I can't even get it to work before being deployed.
Any help would be appreciated, thanks.
UPDATE
Gayot Fow's answer lead me to resolve the problem with the static method
JumpList.AddToRecentCategory(jt);
not doing anything.
I changed my AddToRecent code as follows:
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();
PROBLEM
Although the issue with recent files is resolved, I still cannot get it to co-exist with a custom category called "Tasks"
On my app startup, I call this code:
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();
}
Once this is called, the Recent category disappears, and any call to add recent items does nothing. I do see my "New Document" task, however :/
Am i approaching this totally wrong? Thanks
Here's a snippet of working code for jump listing...
In App.xaml...
<JumpList.JumpList>
<JumpList
ShowFrequentCategory="False"
ShowRecentCategory="False"
JumpItemsRejected="OnJumpItemsRejected"
JumpItemsRemovedByUser="OnJumpItemsRemoved">
</JumpList>
</JumpList.JumpList>
in App.xaml.cs
private void OnJumpItemsRejected(object sender, JumpItemsRejectedEventArgs e){}
private void OnJumpItemsRemoved(object sender, JumpItemsRemovedEventArgs e){}
in code...
public object PopulateJumpList(string directoryName)
{
try
{
string programLocation = Assembly.GetCallingAssembly().Location;
var di = new DirectoryInfo(directoryName);
var jt = new JumpTask
{
ApplicationPath = programLocation,
Arguments = directoryName,
Description = "Run at " + directoryName,
IconResourcePath = programLocation,
Title = di.Name
};
JumpList.AddToRecentCategory(jt);
return jt;
}
catch (Exception ex)
{
return ex;
}
}
this method creates a jump task of the form...
full executable path of the program |=> name of the directory where it was invoked
...this is added to the recent category via the static method AddToRecentCategory. It contrasts to your code where you are adding the task to the local copy of the jump list. The fully qualified name of the executable must be given for the application path. Also, as mentioned in the commentary, it seems to work best when it settles into its own installation directory, and the jump list will be deleted each time the executable is overwritten. Using it in debug mode (against the vshost.exe) will not work reliably.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With