WPF 4 开发Windows 7 跳转列表(JumpList)
原文: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)的更多相关文章
- WPF 4 开发Windows 7 任务栏(Overlay Icon、Thumbnail Toolbar、Progress Bar)
原文:WPF 4 开发Windows 7 任务栏(Overlay Icon.Thumbnail Toolbar.Progress Bar) 在上一篇我们介绍了如何在WPF 4 中开发Wind ...
- 为 WPF 程序添加 Windows 跳转列表的支持
原文:为 WPF 程序添加 Windows 跳转列表的支持 Windows 跳转列表是自 Windows 7 时代就带来的功能,这一功能是跟随 Windows 7 的任务栏而发布的.当时应用程序要想用 ...
- 【Win10】探索 Windows 10 10586 之 JumpList(跳转列表)
Windows 10 10586 出来了也挺久的了,应该大部分都从 10240 升级到这个版本了.在 10586 中,微软添加了 200 多个新的 API,具体 API 的变动,大家可以点击下面这个链 ...
- 使用Visual Studio 2015 Community 开发windows服务
昨天研究在.NET下开发Windows服务程序,期间遇到一些小问题,这里仅将自己的开发过程和需要注意的地方写下和广大网友分享…… 1.基础 Windows服务是指系统启动时能够自己运行的程序.W ...
- .net core 开发 Windows Forms 程序
我是一名 ASP.NET 程序员,专注于 B/S 项目开发.累计文章阅读量超过一千万,我的博客主页地址:https://www.itsvse.com/blog_xzz.html 引言 .net cor ...
- WPF学习开发客户端软件-任务助手(下 2015年2月4日代码更新)
时光如梭,距离第一次写的 WPF学习开发客户端软件-任务助手(已上传源码) 已有三个多月,期间我断断续续地对该项目做了优化.完善等等工作,现在重新向大家介绍一下,希望各位可以使用,本软件以实用性为主 ...
- WPF学习开发客户端软件-任务助手(已上传源码)
本人纯属WPF新手,布局和WPF的开发水平相当欠缺,从个人来说,还是比较喜欢WPF的,有人说WPF是界面加上WINFORM,我不这样认为,WPF与WINFORM主要的不同在于数据绑定. 这个软件虽 ...
- 关于开发Windows服务程序容易搞混的地方!
在开发Windows服务程序时,我们一般需要添加安装程序,即:serviceInstaller,里面有几个关于名称属性,你都搞明白了吗? 1.Description:表示服务说明(描述服务是干什么的) ...
- Selenium2学习-001-Selenium2 WebUI自动化Java开发 Windows 环境配置
此文主要介绍 Selenium2 WebUI自动化Java开发 Windows 环境配置,供各位亲们参考,若有不足之处,敬请各位大神指正,非常感谢! 所需软件列表如下所示: 所属分类 具体名称 备注 ...
随机推荐
- CRT(C Runtime Library)—— C/C++运行时库
C runtime library(part of the C standard library) 任何一个 C 程序,它的背后都有一套庞大的代码来进行支撑,使得该程序得以运行在更高级别上,而不必担心 ...
- AngularJS之forEach
angular.forEach 描述: 循环对obj对象的每个元素调用iterator, obj对象可以是一个Object或一个Array. Iterator函数调用方法: iterator( ...
- [Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def
What about the situation in which we aren’t specifying the number of columns or rows to be repeated? ...
- 【u025】贝茜的晨练计划
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= ...
- MySQL crash-safe replication
MySQL数据库的成功离不开其replicaiton,相对于Oracle DG和Microsoft SQL Server Log Shipping来说,其简单易上手,基本上1,2分钟内根据手册就能完成 ...
- RoundingMode 几个参数详解
第一版 java.math.RoundingMode 几个参数详解 java.math.RoundingMode里面有几个参数搞得我有点晕,现以个人理解对其一一进行总结: 为了能更好理解,我们可以画一 ...
- js如何遍历表单所有控件
js如何遍历表单所有控件 一.总结 一句话总结: 1.获取form表单里面的的所有元素:通过formelement.elements,这里form元素通过name属性直接定位 var fele=for ...
- 如何在使Xcode打包iOS应用时自动增加编译号
在红框标注的输入框中输入:真机调试编译成功增加 echo $CONFIGURATION if [ "Release" == "${CONFIGURATION}" ...
- 谈谈android缓存文件
##内部存储 总是可用的 这里的文件默认是只能被你的app所访问的. 当用户卸载你的app的时候,系统会把internal里面的相关文件都清除干净. Internal是在你想确保不被用户与其他app所 ...
- Cordova app 检查更新 ----创建项目、添加插件、修改插件(一)
原文:Cordova app 检查更新 ----创建项目.添加插件.修改插件(一) 使用Cordova 进行跨平台应用程序的开发 1.创建Cordova项目 $ cordova create hell ...