JumpList JumpList JumpList JumpList Class

定义

表示作为菜单显示在 Windows 7 任务栏按钮上的项和任务的列表。Represents a list of items and tasks displayed as a menu on a Windows 7 taskbar button.

public ref class JumpList sealed : System::ComponentModel::ISupportInitialize
[System.Security.SecurityCritical]
[System.Windows.Markup.ContentProperty("JumpItems")]
public sealed class JumpList : System.ComponentModel.ISupportInitialize
type JumpList = class
    interface ISupportInitialize
Public NotInheritable Class JumpList
Implements ISupportInitialize
继承
JumpListJumpListJumpListJumpList
属性
实现

示例

下面的示例演示具有跳转列表的应用程序。The following example shows an application with a Jump List. 该应用程序,可以将任务添加到当前的跳转列表,请清除的跳转列表中,内容,将新的跳转列表应用到应用程序的三个按钮。The application has three buttons that enable you to add a task to the current Jump List, clear the contents of the Jump List, and apply a new Jump List to the application.

下面的示例演示如何声明JumpList标记中。The following example shows how to declare a JumpList in markup. JumpList包含两个JumpTask链接,另一个JumpPathThe JumpList contains two JumpTask links and one JumpPath. 将应用JumpPath向 shell 将失败如果应用程序未注册为处理.txt 文件扩展名。Applying the JumpPath to the shell will fail if the application is not registered to handle the .txt file name extension.

<Application x:Class="JumpListSample.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <JumpList.JumpList>
        <JumpList ShowRecentCategory="True"
                  ShowFrequentCategory="True"
                  JumpItemsRejected="JumpList_JumpItemsRejected"
                  JumpItemsRemovedByUser="JumpList_JumpItemsRemovedByUser">
            <JumpTask Title="Notepad" 
                      Description="Open Notepad." 
                      ApplicationPath="C:\Windows\notepad.exe"
                      IconResourcePath="C:\Windows\notepad.exe"/>
            <JumpTask Title="Read Me" 
                      Description="Open readme.txt in Notepad." 
                      ApplicationPath="C:\Windows\notepad.exe"
                      IconResourcePath="C:\Windows\System32\imageres.dll"
                      IconResourceIndex="14"
                      WorkingDirectory="C:\Users\Public\Documents"
                      Arguments="readme.txt"/>
            <JumpPath Path="C:\Users\Public\Documents\readme.txt" />
        </JumpList>
    </JumpList.JumpList>
</Application>

下面的示例演示的代码隐藏页App.xamlThe following example shows the code-behind page for App.xaml. 此代码处理JumpItemsRejectedJumpItemsRemovedByUser事件。This code handles the JumpItemsRejected and JumpItemsRemovedByUser events.

using System.Text;
using System.Windows;
using System.Windows.Shell;

namespace JumpListSample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private void JumpList_JumpItemsRejected(object sender, System.Windows.Shell.JumpItemsRejectedEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0} Jump Items Rejected:\n", e.RejectionReasons.Count);
            for (int i = 0; i < e.RejectionReasons.Count; ++i)
            {
                if (e.RejectedItems[i].GetType() == typeof(JumpPath))
                    sb.AppendFormat("Reason: {0}\tItem: {1}\n", e.RejectionReasons[i], ((JumpPath)e.RejectedItems[i]).Path);
                else
                    sb.AppendFormat("Reason: {0}\tItem: {1}\n", e.RejectionReasons[i], ((JumpTask)e.RejectedItems[i]).ApplicationPath);
            }

            MessageBox.Show(sb.ToString());
        }

        private void JumpList_JumpItemsRemovedByUser(object sender, System.Windows.Shell.JumpItemsRemovedEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0} Jump Items Removed by the user:\n", e.RemovedItems.Count);
            for (int i = 0; i < e.RemovedItems.Count; ++i)
            {
                sb.AppendFormat("{0}\n", e.RemovedItems[i]);
            }

            MessageBox.Show(sb.ToString());
        }
    }
}

以下示例演示用于创建应用程序用户界面的标记。The following example shows the markup used to create the application user interface.

<Window x:Class="JumpListSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Jump List Sample" Height="240" Width="500">
    <Window.Resources>
        <Style TargetType="Button">
            <Setter Property="Width" Value="200" />
            <Setter Property="Margin" Value="5" />
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Button Content="Add Task to JumpList" Click="AddTask" />
            <Button Content="Clear Jump List" Click="ClearJumpList"/>
            <Button Content="Set New Jump List" Click="SetNewJumpList" />
        </StackPanel>
    </Grid>
</Window>

下面的示例演示的代码隐藏页MainWindow.xamlThe following example shows the code-behind page for MainWindow.xaml. 此代码演示了如何修改、 清除和创建JumpList在程序代码中。This code demonstrates how to modify, clear, and create a JumpList in procedural code. 有关新跳转列表,静态SetJumpList方法调用以将相关联JumpList与当前应用程序,并将应用JumpList到 Windows shell。For the new Jump List, the static SetJumpList method is called to associate the JumpList with the current application and apply the JumpList to the Windows shell.

using System;
using System.IO;
using System.Windows;
using System.Windows.Shell;

namespace JumpListSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void AddTask(object sender, RoutedEventArgs e)
        {
            // Configure a new JumpTask.
            JumpTask jumpTask1 = new JumpTask();
            // Get the path to Calculator and set the JumpTask properties.
            jumpTask1.ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "calc.exe");
            jumpTask1.IconResourcePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "calc.exe");
            jumpTask1.Title = "Calculator";
            jumpTask1.Description = "Open Calculator.";
            jumpTask1.CustomCategory = "User Added Tasks";
            // Get the JumpList from the application and update it.
            JumpList jumpList1 = JumpList.GetJumpList(App.Current);
            jumpList1.JumpItems.Add(jumpTask1);
            JumpList.AddToRecentCategory(jumpTask1);
            jumpList1.Apply();
        }
        private void ClearJumpList(object sender, RoutedEventArgs e)
        {
            JumpList jumpList1 = JumpList.GetJumpList(App.Current);
            jumpList1.JumpItems.Clear();
            jumpList1.Apply();
        }
        private void SetNewJumpList(object sender, RoutedEventArgs e)
        {
            //Configure a new JumpTask
            JumpTask jumpTask1 = new JumpTask();
            // Get the path to WordPad and set the JumpTask properties.
            jumpTask1.ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "write.exe");
            jumpTask1.IconResourcePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "write.exe");
            jumpTask1.Title = "WordPad";
            jumpTask1.Description = "Open WordPad.";
            jumpTask1.CustomCategory = "Jump List 2";
            // Create and set the new JumpList.
            JumpList jumpList2 = new JumpList();
            jumpList2.JumpItems.Add(jumpTask1);
            JumpList.SetJumpList(App.Current, jumpList2);
        }
    }
}

注解

Windows 7Windows 7任务栏提供了用于直接从任务栏按钮启动程序,通过使用跳转列表的增强的功能。The Windows 7Windows 7 taskbar provides enhanced functionality for starting programs directly from the taskbar button by using Jump Lists. 跳转列表中还使用Windows 7Windows 7开始菜单。Jump Lists are also used in the Windows 7Windows 7 Start menu. 通过右键单击任务栏按钮或单击开始菜单中的某个程序旁边的箭头访问跳转列表。You access a Jump List by right-clicking a taskbar button or by clicking the arrow next to a program in the Start menu. 跳转列表的详细信息,请参阅任务栏部分中的 Windows 用户体验交互准则。For more information about Jump Lists, see the Taskbar section of the Windows User Experience Interaction Guidelines.

JumpList类中的跳转列表功能提供托管的包装Windows 7Windows 7任务栏并管理数据传递给WindowsWindowsshell。The JumpList class provides a managed wrapper for the Jump List functionality in the Windows 7Windows 7 taskbar and manages the data passed to the WindowsWindows shell. 提供的功能JumpList类不是版本中可用WindowsWindows早于Windows 7Windows 7The functionality exposed by the JumpList class is not available in versions of WindowsWindows earlier than Windows 7Windows 7. 使用的应用程序JumpList类的其他版本中将运行WindowsWindows,但不是能跳转列表。Applications that use the JumpList class will run in other versions of WindowsWindows, but the Jump List will not be available. 有关 Windows shell 和本机跳转列表 Api 的详细信息,请参阅任务栏扩展For more information about the Windows shell and native Jump List APIs, see Taskbar Extensions.

下图显示了跳转列表的 Windows Media Player,与中的项任务频繁类别。The following illustration shows the Jump List for Windows Media Player, with items in the Tasks and Frequent categories.

Windows Media Player 跳跃Windows Media Player Jump List
Windows Media Player 跳跃菜单Windows Media Player Jump List

配置跳转列表Configuring a Jump List

跳转列表可以包含两种类型的项,JumpTask和一个JumpPathJump Lists can contain two types of items, a JumpTask and a JumpPath. 一个JumpTask是一个链接到程序和一个JumpPath是指向文件的链接。A JumpTask is a link to a program and a JumpPath is a link to a file. 通过创建来直观地分隔跳转列表中的项JumpTask不具有TitleCustomCategory指定。You can visually separate items in a Jump List by creating a JumpTask that does not have a Title and CustomCategory specified. 此空JumpTask将显示为一条水平线跳转列表中。This empty JumpTask will be displayed as a horizontal line in the Jump List.

备注

如果在指定的文件类型JumpPath未注册应用程序后,该文件不会出现在跳转列表。If the type of the file specified in a JumpPath is not registered with your application, the file will not appear in the Jump List. 例如,如果您添加JumpPath指向.txt 文件,必须注册您的应用程序来处理.txt 文件。For example, if you add a JumpPath that points to a .txt file, your application must be registered to handle .txt files. 有关详细信息,请参阅简介文件关联For more information, see Introduction to File Associations.

跳转项放入中的类别JumpListJump items are placed into categories in the JumpList. 默认情况下,JumpItem 显示在“任务”类别中。By default, a JumpItem is displayed in the Tasks category. 或者,可以指定CustomCategoryJumpItemAlternatively, you can specify a CustomCategory for the JumpItem.

可以指定是否在标准最近频繁中的显示类别JumpList通过设置ShowRecentCategoryShowFrequentCategory属性。You can specify whether the standard Recent and Frequent categories are displayed in the JumpList by setting the ShowRecentCategory and ShowFrequentCategory properties. 这些类别中的内容管理的WindowsWindowsshell。The contents of these categories are managed by the WindowsWindows shell. 因为这些类别中可能包含许多相同的数据,通常显示的一个或另一端是你JumpList,但不可同时使用两者。Because these categories might contain much of the same data, you typically display one or the other in your JumpList, but not both. WindowsWindows 如果通过公共文件对话框打开或用来打开通过文件类型关联的应用程序将自动管理最近使用的项目。automatically manages recent items if they are opened through a common file dialog box or used to open an application through file type association. 通过跳转列表访问某一项,可以通知WindowsWindows外壳程序以将项添加到最近通过调用类别AddToRecentCategory方法。When an item is accessed through the Jump List, you can notify the WindowsWindows shell to add the item to the Recent category by calling the AddToRecentCategory method.

将跳转列表应用到 Windows ShellApplying a Jump List to the Windows Shell

不能直接访问 shell 的跳转列表或其内容读入JumpList类。You cannot access the shell's Jump List directly or read its contents into the JumpList class. 相反,JumpList类提供的表示形式跳转列表,可以使用,并将应用到WindowsWindowsshell。Instead, the JumpList class provides a representation of a Jump List that you can work with, and then apply to the WindowsWindows shell. 通常创建JumpList并将其设置一次当首次运行该应用程序。You typically create a JumpList and set it one time when the application is first run. 但是,您可以修改或替换JumpList在运行时。However, you can modify or replace the JumpList at run time.

如果已设置JumpList属性,你必须应用JumpList到 Windows shell 之前其内容将出现在任务栏跳转列表中。When you have set the JumpList properties, you must apply the JumpList to the Windows shell before its contents appear in the taskbar Jump List. 这自动完成时JumpList首次附加到应用程序,在 XAML 中或在调用SetJumpList方法。This is done automatically when the JumpList is first attached to an application, either in XAML or in a call to the SetJumpList method. 如果您修改的内容JumpList在运行时,必须调用Apply方法以将其当前的内容应用到 Windows shell。If you modify the contents of the JumpList at run time, you must call the Apply method to apply its current contents to the Windows shell.

在 XAML 中设置跳转列表Setting a Jump List in XAML

一个JumpList不会自动附加到Application对象。A JumpList is not automatically attached to an Application object. 附加JumpListApplication对象在 XAML 中的使用附加的属性语法。You attach a JumpList to an Application object in XAML by using the attached property syntax. JumpList类实现ISupportInitialize接口以支持 XAML 声明JumpListThe JumpList class implements the ISupportInitialize interface to support XAML declaration of a JumpList. 如果JumpList是在 XAML 中声明,附加到当前Application,它将自动应用于WindowsWindowsshell 时JumpList初始化。If the JumpList is declared in XAML and attached to the current Application, it is automatically applied to the WindowsWindows shell when the JumpList is initialized.

设置和修改代码中的跳转列表Setting and Modifying a Jump List in Code

附加JumpListApplication对象在代码中通过调用静态SetJumpList方法。You attach a JumpList to an Application object in code by calling the static SetJumpList method. 这同样适用JumpListWindowsWindowsshell。This also applies the JumpList to the WindowsWindows shell.

若要修改JumpList在运行时,调用GetJumpList方法来获取JumpList当前附加到ApplicationTo modify a JumpList at run time, you call the GetJumpList method to get the JumpList that is currently attached to an Application. 已修改的属性后JumpList,必须调用Apply方法以将更改应用于 Windows shell。After you have modified the properties of the JumpList, you must call the Apply method to apply the changes to the Windows shell.

备注

您通常创建一个JumpList附加到Application并将应用于WindowsWindowsshell。You typically create one JumpList that is attached to the Application and applied to the WindowsWindows shell. 但是,你可以创建多个JumpList对象。However, you can create multiple JumpList objects. 只有一个JumpList一次可应用于WindowsWindowsshell 中,也只有一个适配器JumpList一次可以关联ApplicationOnly one JumpList at a time can be applied to the WindowsWindows shell, and only one JumpList at a time can be associated with an Application. .NET Framework 不要求这些是相同JumpListThe .NET Framework does not require that these be the same JumpList.

备注

此类包含在类级别应用于所有成员的链接要求。This class contains a link demand at the class level that applies to all members. 一个SecurityException直接调用方没有完全信任权限时引发。A SecurityException is thrown when the immediate caller does not have full-trust permission. 有关安全要求的详细信息,请参阅链接需求继承需求For more information about security demands, see Link Demands and Inheritance Demands.

构造函数

JumpList() JumpList() JumpList() JumpList()

初始化 JumpList 类的新实例。Initializes a new instance of the JumpList class.

JumpList(IEnumerable<JumpItem>, Boolean, Boolean) JumpList(IEnumerable<JumpItem>, Boolean, Boolean) JumpList(IEnumerable<JumpItem>, Boolean, Boolean) JumpList(IEnumerable<JumpItem>, Boolean, Boolean)

使用指定的参数初始化 JumpList 类的新实例。Initializes a new instance of the JumpList class with the specified parameters.

属性

JumpItems JumpItems JumpItems JumpItems

获取集合的JumpItem跳转列表中显示的对象。Gets the collection of JumpItem objects that are displayed in the Jump List.

ShowFrequentCategory ShowFrequentCategory ShowFrequentCategory ShowFrequentCategory

获取或设置一个值,指示常用的项是否显示在跳转列表。Gets or sets a value that indicates whether frequently used items are displayed in the Jump List.

ShowRecentCategory ShowRecentCategory ShowRecentCategory ShowRecentCategory

获取或设置一个值,指示是否跳转列表中显示最近使用的项。Gets or sets a value that indicates whether recently used items are displayed in the Jump List.

方法

AddToRecentCategory(JumpPath) AddToRecentCategory(JumpPath) AddToRecentCategory(JumpPath) AddToRecentCategory(JumpPath)

将指定的跳转路径添加到跳转列表的“最近”类别中。Adds the specified jump path to the Recent category of the Jump List.

AddToRecentCategory(JumpTask) AddToRecentCategory(JumpTask) AddToRecentCategory(JumpTask) AddToRecentCategory(JumpTask)

将指定的跳转任务添加到跳转列表的“最近”类别中。Adds the specified jump task to the Recent category of the Jump List.

AddToRecentCategory(String) AddToRecentCategory(String) AddToRecentCategory(String) AddToRecentCategory(String)

将指定的项路径添加到跳转列表的“最近”类别中。Adds the specified item path to the Recent category of the Jump List.

Apply() Apply() Apply() Apply()

将发送JumpList的 Windows shell 中其当前状态。Sends the JumpList to the Windows shell in its current state.

BeginInit() BeginInit() BeginInit() BeginInit()

表示开始JumpList初始化。Signals the start of the JumpList initialization.

EndInit() EndInit() EndInit() EndInit()

表示结束JumpList初始化。Signals the end of the JumpList initialization.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetJumpList(Application) GetJumpList(Application) GetJumpList(Application) GetJumpList(Application)

返回JumpList与应用程序相关联的对象。Returns the JumpList object associated with an application.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
SetJumpList(Application, JumpList) SetJumpList(Application, JumpList) SetJumpList(Application, JumpList) SetJumpList(Application, JumpList)

JumpList与应用程序相关联的对象。Sets the JumpList object associated with an application.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

事件

JumpItemsRejected JumpItemsRejected JumpItemsRejected JumpItemsRejected

跳转项未成功添加到跳转列表由 Windows shell 时发生。Occurs when jump items are not successfully added to the Jump List by the Windows shell.

JumpItemsRemovedByUser JumpItemsRemovedByUser JumpItemsRemovedByUser JumpItemsRemovedByUser

以前在跳转列表中的跳转项由用户从列表中删除时发生。Occurs when jump items previously in the Jump List are removed from the list by the user.

安全性

UIPermission
若要修改 Windows shell 的完全访问权限。for full access to modify the Windows shell. 安全操作: LinkDemandSecurity action: LinkDemand. 关联的枚举: AllWindowsAssociated enumeration: AllWindows

适用于