In my previous posts I’ve demonstrated how to customize the Windows 7 Taskbar Jumplist with custom icons and actions. In this post I would like to show how to leverage XAML Markup Extensions to pick the right assembly name for both the application full path and icon resource full path.
One real bizarre thing in the WPF Jumplist is that there is no option to initialize some Jumplist properties after created from XAML. For example: The JumplistTask application path. The only option is to create the whole Jumplist from code behind (Horrible…).
So I had an idea to use XAML markup extensions to do this job and stay in XAML.
<JumpList.JumpList>
<JumpList ShowRecentCategory="True"
ShowFrequentCategory="True">
<JumpTask Title="Say Hello!"
Description="Display Greeting Message"
ApplicationPath="{local:ApplicationFullPath}"
Arguments="{x:Static local:ApplicationActions.SayHello}"
IconResourcePath="{local:ApplicationFullPath}"
IconResourceIndex="0" />
</JumpList>
</JumpList.JumpList>
And the markup-extension looks like this:
/// <summary>
/// Provides executing assembly full path.
/// </summary>
public class ApplicationFullPath : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return Assembly.GetExecutingAssembly().Location;
}
}
Of course you can create something more sophisticated with arguments and more logic, but this little one does the job and your code stays clean.
Feel free to download the code from here.