在之前寫過的《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>