JumpList 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示項目及工作清單,此項目及工作會顯示成為 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
- 屬性
- 實作
範例
下列範例顯示具有跳躍清單的應用程式。 應用程式有三個按鈕,可讓您將工作新增至目前的跳躍清單、清除跳躍清單的內容,並將新的跳躍清單套用至應用程式。
下列範例示範如何在標記中宣告 JumpList 。 JumpList包含兩 JumpTask 個連結和一個 JumpPath 。 JumpPath如果未註冊應用程式來處理.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
代碼後置頁面。 此程式碼會處理 JumpItemsRejected 和 JumpItemsRemovedByUser 事件。
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 程式碼中的 。 針對新的 Jump List,會呼叫靜態 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 Media Player 跳躍清單
設定跳躍清單
跳躍清單可以包含兩種類型的專案:和 JumpTaskJumpPath 。 JumpTask是程式的連結,而 JumpPath 是檔案的連結。 您可以建立沒有 Title 和 CustomCategory 指定的 , JumpTask 以視覺化方式分隔跳躍清單中的專案。 這個空白 JumpTask 會顯示為跳躍清單中的水平線。
注意
如果 中指定的 JumpPath 檔案類型未向您的應用程式註冊,則檔案不會出現在跳躍清單中。 例如,如果您新增 JumpPath 指向 .txt 檔案的 ,則必須註冊您的應用程式來處理.txt檔案。 如需詳細資訊,請參閱 檔案關聯簡介。
跳躍專案會放在 中的 JumpList 類別中。 根據預設,會在 JumpItem [ 工作 ] 類別中顯示 。 或者,您可以為 JumpItem 指定 CustomCategory 。
您可以藉由設定 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 物件。 您可以使用附加屬性語法,將 附加 JumpList 至 Application XAML 中的 物件。 類別 JumpList 會實作 ISupportInitialize 介面,以支援 的 JumpList XAML 宣告。 JumpList如果在 XAML 中宣告 ,並附加至目前的 Application ,則會在 初始化 時 JumpList 自動套用至 Windows 殼層。
在程式碼中設定和修改跳躍清單
您可以藉由呼叫靜態 SetJumpList 方法,將 附加 JumpList 至 Application 程式碼中的 物件。 這也適用于 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 |
發生於已由使用者從清單中移除先前在跳躍清單中的跳躍項目時。 |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應