JumpList 類別

定義

表示項目及工作清單,此項目及工作會顯示成為 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
繼承
JumpList
屬性
實作

範例

下列範例顯示具有跳躍清單的應用程式。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.

下列範例顯示如何在標記中宣告 JumpListThe following example shows how to declare a JumpList in markup. JumpList 包含兩個 JumpTask 連結和一個 JumpPathThe JumpList contains two JumpTask links and one JumpPath. 如果未註冊應用程式來處理 .txt 副檔名,將 JumpPath 套用至 shell 將會失敗。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.xaml的程式碼後置頁面。The 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.xaml的程式碼後置頁面。The following example shows the code-behind page for MainWindow.xaml. 這段程式碼示範如何在程式性程式碼中修改、清除和建立 JumpListThis 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 工作列中的跳躍清單功能提供 managed 包裝函式,並管理傳遞至 WindowsWindows shell 的資料。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 類別所公開的功能,在 Windows 7Windows 7之前的 WindowsWindows 版本中無法使用。The 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 媒體播放機的跳躍清單,其中包含 [工作] 和 [常用] 分類中的專案The following illustration shows the Jump List for Windows Media Player, with items in the Tasks and Frequent categories.

Windows 媒體播放機跳躍清單Windows Media Player Jump List
Windows Media Player 跳躍清單Windows Media Player Jump List

設定跳躍清單Configuring a Jump List

跳躍清單可以包含兩種類型的專案: JumpTaskJumpPathJump 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. 您可以藉由建立未指定 TitleCustomCategoryJumpTask,以視覺化方式分隔跳躍清單中的專案。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. 例如,如果您加入指向 .txt 檔案的 JumpPath,則必須註冊您的應用程式以處理 .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.

跳躍專案會放入 JumpList的類別中。Jump items are placed into categories in the JumpList. 根據預設,JumpItem 會顯示在 [工作] 分類中。By default, a JumpItem is displayed in the Tasks category. 或者,您也可以指定 JumpItemCustomCategoryAlternatively, you can specify a CustomCategory for the JumpItem.

您可以藉由設定 ShowRecentCategoryShowFrequentCategory 屬性,指定是否要在 JumpList 中顯示標準最近經常分類的類別。You can specify whether the standard Recent and Frequent categories are displayed in the JumpList by setting the ShowRecentCategory and ShowFrequentCategory properties. 這些類別的內容是由 WindowsWindows shell 所管理。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. 透過跳躍清單存取專案時,您可以藉由呼叫 AddToRecentCategory 方法,通知 WindowsWindows shell 將專案新增至 [最近] 分類。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 類別會提供可供您使用的跳躍清單標記法,然後套用至 WindowsWindows shell。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. 不過,您可以在執行時間修改或取代 JumpListHowever, 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. 您可以使用附加屬性語法,將 JumpList 附加至 XAML 中的 Application 物件。You attach a JumpList to an Application object in XAML by using the attached property syntax. JumpList 類別會執行 ISupportInitialize 介面,以支援 JumpList的 XAML 宣告。The JumpList class implements the ISupportInitialize interface to support XAML declaration of a JumpList. 如果 JumpList 是在 XAML 中宣告並附加到目前的 Application,則當 JumpList 初始化時,它會自動套用至 WindowsWindows shell。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

藉由呼叫靜態 SetJumpList 方法,您可以在程式碼中將 JumpList 附加至 Application 物件。You attach a JumpList to an Application object in code by calling the static SetJumpList method. 這也會將 JumpList 套用至 WindowsWindows shell。This also applies the JumpList to the WindowsWindows shell.

若要在執行時間修改 JumpList,您可以呼叫 GetJumpList 方法,以取得目前附加至 ApplicationJumpListTo 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.

注意

您通常會建立一個附加至 ApplicationJumpList,並套用至 WindowsWindows shell。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 可以套用至 WindowsWindows shell,而且一次只能有一個 JumpListApplication相關聯。Only 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. 當立即呼叫端沒有完全信任許可權時,就會擲回 SecurityExceptionA 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 類別的新執行個體。Initializes a new instance of the JumpList class.

JumpList(IEnumerable<JumpItem>, Boolean, Boolean)

使用指定的參數,初始化 JumpList 類別的新執行個體。Initializes a new instance of the JumpList class with the specified parameters.

屬性

JumpItems

取得 JumpItem 物件的集合,這些物件會顯示在跳躍清單中。Gets the collection of JumpItem objects that are displayed in the Jump List.

ShowFrequentCategory

取得或設定值,這個值指出是否在跳躍清單中顯示經常使用的項目。Gets or sets a value that indicates whether frequently used items are displayed in the Jump List.

ShowRecentCategory

取得或設定值,這個值指出是否在跳躍清單中顯示最近使用的項目。Gets or sets a value that indicates whether recently used items are displayed in the Jump List.

方法

AddToRecentCategory(JumpPath)

將指定的跳躍路徑加入至跳躍清單的 [最近] 分類中。Adds the specified jump path to the Recent category of the Jump List.

AddToRecentCategory(JumpTask)

將指定的跳躍工作加入至跳躍清單的 [最近] 分類中。Adds the specified jump task to the Recent category of the Jump List.

AddToRecentCategory(String)

將指定的項目路徑加入至跳躍清單的 [最近] 分類中。Adds the specified item path to the Recent category of the Jump List.

Apply()

將目前狀態中的 JumpList 傳送至 Windows Shell。Sends the JumpList to the Windows shell in its current state.

BeginInit()

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

EndInit()

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

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetJumpList(Application)

傳回與應用程式相關聯的 JumpList 物件。Returns the JumpList object associated with an application.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
SetJumpList(Application, JumpList)

設定與應用程式相關聯的 JumpList 物件。Sets the JumpList object associated with an application.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

JumpItemsRejected

發生於無法由 Windows Shell 將跳躍項目加入至跳躍清單時。Occurs when jump items are not successfully added to the Jump List by the Windows shell.

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

適用於