DotNET平台下添加JumpList

发表于:2013-7-04 10:25

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:贝神    来源:51Testing软件测试网采编

  XAML

<span style="font-size:10px;"> <!--using System.Windows.Shell;-->
   
<Application x:Class="WpfApplication.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>
            <JumpTask
                    Title="Open Notepad"
                    Description="Open the Notepad Application"
                    IconResourcePath="C:\Windows\Notepad.exe"
                    IconResourceIndex="0"
                    ApplicationPath="C:\Windows\Notepad.exe" />
        </JumpList>
    </JumpList.JumpList>
</Application></span><span style="font-size:24px;color: rgb(255, 0, 0); ">
</span>

  CSharp:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace WpfApplication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            // 创建一个新的JumpList
            JumpTask _JumpTask = new JumpTask();

            _JumpTask.Title = "Open Notepad";
            _JumpTask.Description = "Open the Notepad Application";
            _JumpTask.ApplicationPath = @"C:\Windows\Notepad.exe";
            _JumpTask.IconResourcePath = @"C:\Windows\Notepad.exe";
            _JumpTask.IconResourceIndex = 0;

            // 获得当前的JumpList
            bool bExist = true;
            JumpList _JumpList = JumpList.GetJumpList(App.Current);
            if (_JumpList == null)
            {
                bExist = false;

                // 创建 JumpList
                _JumpList = new JumpList();
            }

            // 添加JumpList
            _JumpList.JumpItems.Add(_JumpTask);

            // 更新
            _JumpList.Apply();

            // 如果之前没有JumpList则加入
            if( !bExist )
            {
                JumpList.SetJumpList(App.Current, _JumpList);
            }
        }
    }
}

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号