原文:WPF 4 开发Windows 7 跳转列表(JumpList)

     在之前写过的《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>

通过阅读上面的程序,很容易看出我们加入了两个应用程序(“记事本”、“画版”)和一个“网站链接”,其中的属性参数使用起来也十分方便。

用C# 编写JumpList

     上面使用XAML 方式编写了一个简单的JumpList,当然C# 同样也能实现相同的效果。首先在MainWindow 中拖入两个Button:

<Window x:Class="Win7TaskbarDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="211" Width="363" Icon="/Win7TaskbarDemo;component/Resources/App.ico"> <Grid>
<Button Content="Clear All Tasks" Height="23" HorizontalAlignment="Right" Margin="0,29,59,0"
Name="ClearBtn" VerticalAlignment="Top" Width="89" Click="ClearBtn_Click" />
<Button Content="Add New Task" Height="23" HorizontalAlignment="Left" Margin="60,29,0,0"
Name="AddBtn" VerticalAlignment="Top" Width="93" Click="AddBtn_Click" />
</Grid>
</Window>

     为它们分别添加点击事件,其中一个是为JumpList 增加“计算器”链接,另一个是将所有链接清空。创建JumpList 时需要使用System.Windows.Shell 命名空间,是不是有点像API 中的Microsoft.WindowsAPICodePack.Shell。

private void AddBtn_Click(object sender, RoutedEventArgs e)
{
JumpTask jumpTask = new JumpTask();
//Create a new Calculator JumpTask
jumpTask.ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");
jumpTask.IconResourcePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");
jumpTask.Title = "Calculator";
jumpTask.Description = "Start Calculator";
jumpTask.CustomCategory = "New Microsoft Tools"; //Add Calculator to JumpList
JumpList jumpList = JumpList.GetJumpList(App.Current);
jumpList.JumpItems.Add(jumpTask);
jumpList.Apply();
} private void ClearBtn_Click(object sender, RoutedEventArgs e)
{
JumpList jumpList1 = JumpList.GetJumpList(App.Current);
jumpList1.JumpItems.Clear();
jumpList1.Apply();
}

分别点击两个按键后的效果:

        

相关参考资料

1.Windows 7 任务栏开发 之 跳转列表(Jump Lists)

http://www.cnblogs.com/gnielee/archive/2010/03/16/windows7-taskbar-jumplists.html

2.What's New in WPF Version 4

http://msdn.microsoft.com/en-us/library/bb613588(VS.100).aspx

3.JumpList Class

http://msdn.microsoft.com/en-us/library/system.windows.shell.jumplist(v=VS.100).aspx

源代码下载

WPF 4 开发Windows 7 跳转列表(JumpList)的更多相关文章

  1. WPF 4 开发Windows 7 任务栏(Overlay Icon、Thumbnail Toolbar、Progress Bar)

    原文:WPF 4 开发Windows 7 任务栏(Overlay Icon.Thumbnail Toolbar.Progress Bar)      在上一篇我们介绍了如何在WPF 4 中开发Wind ...

  2. 为 WPF 程序添加 Windows 跳转列表的支持

    原文:为 WPF 程序添加 Windows 跳转列表的支持 Windows 跳转列表是自 Windows 7 时代就带来的功能,这一功能是跟随 Windows 7 的任务栏而发布的.当时应用程序要想用 ...

  3. 【Win10】探索 Windows 10 10586 之 JumpList(跳转列表)

    Windows 10 10586 出来了也挺久的了,应该大部分都从 10240 升级到这个版本了.在 10586 中,微软添加了 200 多个新的 API,具体 API 的变动,大家可以点击下面这个链 ...

  4. 使用Visual Studio 2015 Community 开发windows服务

    昨天研究在.NET下开发Windows服务程序,期间遇到一些小问题,这里仅将自己的开发过程和需要注意的地方写下和广大网友分享……  1.基础   Windows服务是指系统启动时能够自己运行的程序.W ...

  5. .net core 开发 Windows Forms 程序

    我是一名 ASP.NET 程序员,专注于 B/S 项目开发.累计文章阅读量超过一千万,我的博客主页地址:https://www.itsvse.com/blog_xzz.html 引言 .net cor ...

  6. WPF学习开发客户端软件-任务助手(下 2015年2月4日代码更新)

    时光如梭,距离第一次写的 WPF学习开发客户端软件-任务助手(已上传源码)  已有三个多月,期间我断断续续地对该项目做了优化.完善等等工作,现在重新向大家介绍一下,希望各位可以使用,本软件以实用性为主 ...

  7. WPF学习开发客户端软件-任务助手(已上传源码)

    本人纯属WPF新手,布局和WPF的开发水平相当欠缺,从个人来说,还是比较喜欢WPF的,有人说WPF是界面加上WINFORM,我不这样认为,WPF与WINFORM主要的不同在于数据绑定.   这个软件虽 ...

  8. 关于开发Windows服务程序容易搞混的地方!

    在开发Windows服务程序时,我们一般需要添加安装程序,即:serviceInstaller,里面有几个关于名称属性,你都搞明白了吗? 1.Description:表示服务说明(描述服务是干什么的) ...

  9. Selenium2学习-001-Selenium2 WebUI自动化Java开发 Windows 环境配置

    此文主要介绍 Selenium2 WebUI自动化Java开发 Windows 环境配置,供各位亲们参考,若有不足之处,敬请各位大神指正,非常感谢! 所需软件列表如下所示: 所属分类 具体名称 备注 ...

随机推荐

  1. thinkphp5项目--练手--企业单车网站(九)(友情链接)

    thinkphp5项目--练手--企业单车网站(九)(友情链接) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Webs ...

  2. css3 border img 边框图片

    摘自http://www.html-js.com/article/CSS3-tutorial-css3borderimage-frame-image-Xiangjie-on border-image摘 ...

  3. Visual Stdio 环境下使用 GSL (GNU Scientific Library)

    Visual Stdio 环境下使用 GSL (GNU Scientific Library) 经測试.这里的方法不适用于VS2015. * 这篇文章有点过时了.建议从以下网址下载能够在 vs 环境下 ...

  4. 小强的HTML5移动开发之路(46)——汇率计算器【2】

    在上一篇中我们完成了汇率计算页面,下面来完成汇率设置页面的显示. <div class="setRates"> <div class="header&q ...

  5. &quot;Swift&quot;编程语言

    来自英文文档.百度翻译以及自己没过4级的渣渣英语功底,为了自己以后看起来方便 About Swift 关于"海燕" IMPORTANT 重要 This is a prelimina ...

  6. ie7span标签float换行悬浮

    项目中,ie8以上都是好好的,就是ie7的布局有问题,span换行漂浮了 <div style="height:20px"> <span style=" ...

  7. php课程 6-24 字符串函数有哪些(复习)

    php课程 6-24 字符串函数有哪些(复习) 一.总结 一句话总结: 二.php课程 6-24 字符串函数有哪些(复习) 上次复习:--------------------------------- ...

  8. Method and apparatus for loading a segment register in a microprocessor capable of operating in multiple modes

    A microprocessor contains an address generation unit, including a segment block, for loading descrip ...

  9. UIPasteboard粘贴板:UITableView复制粘贴功能(二)

    这篇咱写写一写在UITableView上实用剪贴板的两种方法: 一:在自定义cell里面使用 其实,在cell的使用跟在label里面的用法基本一样 1.放方法: - (BOOL)canBecomeF ...

  10. jQuery实现复选框的全选、反选、并且根据复选框的<checked属性>控制多个对应div的显示/隐藏

    <!doctype html><html> <head> <meta charset="utf-8"> <title>j ...