Welcome

首页 / 软件开发 / .NET编程技术 / WPF 4 开发Windows 7 跳转列表(JumpList)

WPF 4 开发Windows 7 跳转列表(JumpList)2011-05-06 博客园 李敬然在之前写过的《Windows 7 任务栏开发系列》中我们通过Visual Studio 2008 借助微软 提供的Windows API Code Pack 对应用程序的任务栏进行开发,即将到来的Visual Studio 2010 为我们提供了更方便的开发方式,新版本的WPF 4 只需要通过XAML 代码即可实现 Windows 7 任务栏的特性。本篇将针对JumpList(跳转列表)进行介绍,同时体验下.NET Framework 4.0 的新功能。

用XAML 编写JumpList

在WPF 4 中开发任务栏的方便之处就在于可以使用XAML 直接编写相应的功能代码,无须 再使用API 编写繁琐的C# 程序。首先打开App.xaml 文件加入我们想要的JumpList 程序, 其中JumpList 类为创建跳转列表提供了方法,JumpTask 类可以创建列表中的链接。可以对 比一下通过API 编写的JumpList,很明显XAML 的方式更为简单清晰。

<Application x:Class="Win7TaskbarDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
<JumpList.JumpList>
<JumpList ShowFrequentCategory="True"
ShowRecentCategory="True">
<JumpTask ApplicationPath="notepad.exe"
CustomCategory="Microsoft Tools"
Description="Start Notepad"
Title="Notepad"
IconResourcePath="notepad.exe"
IconResourceIndex="0" />

<JumpTask ApplicationPath="mspaint.exe"
CustomCategory="Microsoft Tools"
Description="Start Paint"
Title="Paint"
IconResourcePath="mspaint.exe"
IconResourceIndex="0" />

<JumpTask ApplicationPath="http://gnielee.cnblogs.com/"
CustomCategory="Blog Link"
Description="Go to {GnieTech}"
Title="Gnie"s Blog"
IconResourcePath="C:\Program Files\Internet Explorer\iexplore.exe" />
</JumpList>
</JumpList.JumpList>
</Application>