共用方式為


JumpList 類別

定義

表示項目及工作清單,此項目及工作會顯示成為 Windows 7 工作列按鈕上的功能表。

public ref class JumpList sealed : System::ComponentModel::ISupportInitialize
[System.Windows.Markup.ContentProperty("JumpItems")]
public sealed class JumpList : System.ComponentModel.ISupportInitialize
[System.Windows.Markup.ContentProperty("JumpItems")]
[System.Security.SecurityCritical]
public sealed class JumpList : System.ComponentModel.ISupportInitialize
[<System.Windows.Markup.ContentProperty("JumpItems")>]
type JumpList = class
    interface ISupportInitialize
[<System.Windows.Markup.ContentProperty("JumpItems")>]
[<System.Security.SecurityCritical>]
type JumpList = class
    interface ISupportInitialize
Public NotInheritable Class JumpList
Implements ISupportInitialize
繼承
JumpList
屬性
實作

範例

下列範例顯示具有跳躍清單的應用程式。 應用程式有三個按鈕,可讓您將工作新增至目前的跳躍清單、清除跳躍清單的內容,並將新的跳躍清單套用至應用程式。

下列範例示範如何在標記中宣告 JumpListJumpList包含兩JumpTask個連結與一個 JumpPathJumpPath如果應用程式未註冊以處理 .txt 擴展名,則套用 至殼層將會失敗。

<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。 此程式代碼會處理 JumpItemsRejectedJumpItemsRemovedByUser 事件。

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());
        }
    }
}

下列範例顯示用來建立應用程式使用者介面的標記。

<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。 此程式代碼示範如何在程式性程式代碼中修改、清除和建立 JumpList 。 針對新的跳躍清單,會呼叫靜態 SetJumpList 方法,將 與目前的應用程式產生關聯 JumpList ,並將套用 JumpList 至 Windows 殼層。

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 7 工作列提供增強的功能,可讓您使用跳躍清單直接從任務欄按鈕啟動程式。 跳躍清單也用於 Windows 7 [開始] 選單中。 您可以在任務欄按鈕上按下滑鼠右鍵,或按下 [開始] 功能表中程式旁的箭號,來存取跳躍清單。 如需跳躍清單的詳細資訊,請參閱 Windows 用戶體驗互動指導方針的 任務列 一節。

類別 JumpList 會為 Windows 7 任務列中的跳躍清單功能提供 Managed 包裝函式,並管理傳遞至 Windows 殼層的數據。 類別公開 JumpList 的功能不適用於 Windows 7 之前的 Windows 版本。 使用 JumpList 類別的應用程式將會在其他版本的 Windows 中執行,但無法使用跳躍清單。 如需 Windows 殼層和原生跳躍清單 API 的詳細資訊,請參閱 任務列延伸模組

下圖顯示 Windows 媒體播放機的跳躍清單,其中包含 [ 工作 ] 和 [ 常用 ] 類別中的專案。

Windows 媒體播放器跳躍清單 Windows
Windows Media Player 跳躍清單

設定跳躍清單

跳躍清單可以包含兩種類型的專案:和 JumpTaskJumpPathJumpTask是程序的連結,而 JumpPath 是檔案的連結。 您可以建立沒有 TitleCustomCategory 指定的 ,JumpTask以可視化方式分隔跳躍清單中的專案。 這個空白 JumpTask 會顯示為跳躍清單中的水平線。

注意

如果 中指定的 JumpPath 檔類型未向您的應用程式註冊,則檔案不會出現在跳躍清單中。 例如,如果您新增 JumpPath 指向 .txt 檔案的 ,則必須註冊您的應用程式來處理 .txt 檔案。 如需詳細資訊,請參閱 檔案關聯簡介

跳躍專案會放在中的類別中 JumpList。 根據預設,會在 JumpItem [ 工作 ] 類別中顯示 。 或者,您可以指定 CustomCategoryJumpItem

您可以藉由設定 ShowRecentCategory 和 屬性,指定 標準 [最近] 和 ShowFrequentCategory [常用] 類別是否顯示在 中JumpList。 這些類別的內容是由 Windows 殼層管理。 因為這些類別可能包含許多相同的數據,所以您通常會在 中 JumpList顯示一個或另一個數據,但不會同時顯示兩者。 Windows 會在透過通用檔案對話框開啟或用來透過檔類型關聯開啟應用程式時,自動管理最近的專案。 透過跳躍清單存取專案時,您可以呼叫 AddToRecentCategory 方法,通知 Windows 殼層將專案新增至 [最近] 類別。

將跳躍清單套用至 Windows 殼層

您無法直接存取殼層的跳躍清單,或將其內容讀入 JumpList 類別。 相反地,類別 JumpList 會提供您可以使用的跳躍清單表示法,然後套用至 Windows 殼層。 您通常會建立 , JumpList 並在應用程式第一次執行時設定它。 不過,您可以在執行時間修改或取代 JumpList

當您設定 JumpList 屬性時,必須先將 套用 JumpList 至 Windows 殼層,其內容才會出現在任務列跳躍清單中。 當 第一次附加至應用程式時 JumpList ,就會在 XAML 或方法呼叫 SetJumpList 中自動完成此作業。 如果您在運行時間修改 的內容 JumpList ,您必須呼叫 Apply 方法,將其目前內容套用至 Windows 殼層。

在 XAML 中設定跳躍清單

JumpList不會自動附加至 Application 物件。 您可以使用附加屬性語法,將 附加 JumpListApplication XAML 中的物件。 類別 JumpList 會實作 ISupportInitialize 介面,以支援的 JumpListXAML 宣告。 JumpList如果在 XAML 中宣告 ,並附加至目前的 Application,則會在 初始化 時JumpList自動套用至 Windows 殼層。

在程式代碼中設定和修改跳躍清單

您可以藉由呼叫靜態SetJumpList方法,將 附加JumpListApplication程式代碼中的物件。 這也適用於 JumpList Windows 殼層。

若要在執行時間修改 JumpList ,您可以呼叫 GetJumpList 方法來取得 JumpList 目前附加至 的 Application。 修改 的屬性 JumpList之後,您必須呼叫 Apply 方法,以將變更套用至 Windows 殼層。

注意

您通常會建立一個 JumpList 附加至 Application 的 ,並套用至 Windows 殼層。 不過,您可以建立多個 JumpList 物件。 一次只能套用一個 JumpList 至 Windows 殼層,一次只能有一個 JumpList 與相關聯 Application。 .NET Framework 不需要這些是相同的 JumpList

注意

此類別包含適用於所有成員之類別層級的連結需求。 SecurityException當立即呼叫端沒有完全信任權限時,會擲回 。 如需安全性需求的詳細資訊,請參閱 連結需求繼承需求

建構函式

JumpList()

初始化 JumpList 類別的新執行個體。

JumpList(IEnumerable<JumpItem>, Boolean, Boolean)

使用指定的參數,初始化 JumpList 類別的新執行個體。

屬性

JumpItems

取得 JumpItem 物件的集合,這些物件會顯示在跳躍清單中。

ShowFrequentCategory

取得或設定值,這個值指出是否在跳躍清單中顯示經常使用的項目。

ShowRecentCategory

取得或設定值,這個值指出是否在跳躍清單中顯示最近使用的項目。

方法

AddToRecentCategory(JumpPath)

將指定的跳躍路徑新增至跳躍清單的 [最近 ] 類別。

AddToRecentCategory(JumpTask)

將指定的跳躍工作新增至跳躍清單的 [最近 ] 類別。

AddToRecentCategory(String)

將指定的項目路徑加入跳躍清單的 [最近 ] 類別。

Apply()

將目前狀態中的 JumpList 傳送至 Windows Shell。

BeginInit()

表示 JumpList 初始化開始。

EndInit()

表示 JumpList 初始化結束。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetJumpList(Application)

傳回與應用程式相關聯的 JumpList 物件。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

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

設定與應用程式相關聯的 JumpList 物件。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

JumpItemsRejected

發生於無法由 Windows Shell 將跳躍項目加入至跳躍清單時。

JumpItemsRemovedByUser

發生於已由使用者從清單中移除先前在跳躍清單中的跳躍項目時。

適用於