• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

WPF4开发Windows7跳转列表(JumpList)

时间:2015年04月02日 15:47:24    来源:魔法猪系统重装大师官网    人气:19934

 在之前写过的《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 的方式更为简单清晰。


    
         
    
    
        
            
            
            

            
        
    

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

用C# 编写JumpList

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


    
    
        

     为它们分别添加点击事件,其中一个是为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();
}

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

        

WPF4,开发,Windows7,跳转,列表,JumpLis
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部