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
源代码下载
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
WPF编游戏系列 之九 物品清单再优化
原文: WPF编游戏系列 之九 物品清单再优化 在“第三篇”和“第四篇”中通过用户控件和数据绑定功能对物品清单进行一些优化减少了部分C#代码,但感觉使用Grid设置物品显示位置实在是太繁琐,而且还要为n个物品重复创建新UserControl很浪费资源,所以决定使用ListBox、UserControl和DataTemplate来对物品清单再优化下,让XAML多干些活而不是总用C#调用UI,这样日后维护起来也方便。 1. 替换掉原来的Gird,将ListBox加入到Window1.xaml中。 <ListBox x:Name="queryList" ItemsPanel="{StaticResource queryListBoxStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0" Background="{Binding WinBackground, Mode=OneWay}" ItemContainerStyle="{StaticResource listBoxItem...
- 下一篇
C# 操作Excel图形——绘制、读取、隐藏、删除图形
简介 本篇文章将介绍C# 如何处理Excel图形相关的问题,包括以下内容要点: 1.绘制图形 1.1 绘制图形并添加文本到图形 1.2 添加图片到图形 1.3 设置图形阴影效果 2. 提取图形中的文本、图片 3. 设置图形的显示、隐藏 4. 删除图形 4.1删除指定图形 4.2 删除所有图形 所需工具 Free Spire.XLS for .NET 8.3 (社区版) PS: 下载安装该类库后,注意在项目程序中添加引用Spire.Xls.dll文件(dll文件可在安装路径下的Bin文件夹中获取) 注:Spire.xls能支持的图形种类很多,常见的Office Excel中的图形,这个类库也都能实现, 示例代码(供参考) 1. 绘制图形 【C#】 using System.Drawing; using Spire.Xls; using Spire.Xls.Core; namespace Add_shapes_to_Excel { class Program { static void Main(string[] args) { //创建实例 Workbook workbook ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- CentOS6,CentOS7官方镜像安装Oracle11G
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题