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 文件扩展名,则向 shell 应用将失败。
<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 过程代码。 对于新的跳转列表,将调用静态 SetJumpList 方法,将 JumpList 与当前应用程序相关联,并将 JumpList 应用到 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 7任务栏通过使用跳转列表直接从任务栏按钮启动程序提供了增强功能。 跳转列表也用于Windows 7“开始”菜单。 可以通过右键单击任务栏按钮或单击“开始”菜单中某个程序旁边的箭头来访问跳转列表。 有关跳转列表的详细信息,请参阅Windows用户体验交互指南的 Taskbar 部分。
JumpList 类为Windows 7任务栏中的跳转列表功能提供托管包装,并管理传递给 Windows shell 的数据。 JumpList 类公开的功能在早于 Windows 7 的 Windows 版本中不可用。 使用 JumpList 类的应用程序将在Windows的其他版本中运行,但跳转列表将不可用。 有关 Windows shell 和本机跳转列表 API 的详细信息,请参阅 Taskbar Extensions。
下图显示了 Windows Media Player 的跳转列表,其中项位于 Tasks 和 Frequent 类别中。
Windows Media Player跳转列表
配置跳转列表
跳转列表可以包含两种类型的项:一 JumpTask 个和一个 JumpPath。 A JumpTask 是指向程序的链接, JumpPath 也是指向文件的链接。 可以通过创建 JumpTask 不包含 Title 和 CustomCategory 指定的项来直观地分隔跳转列表中的项。 此空 JumpTask 值将显示为跳转列表中的水平线。
注释
如果应用程序中 JumpPath 指定的文件类型未注册到应用程序,该文件将不会显示在跳转列表中。 例如,如果添加指向 .txt 文件的终结点 JumpPath ,则必须注册应用程序来处理 .txt 文件。 有关详细信息,请参阅 “文件关联简介”。
跳转项将放入类别中 JumpList。 默认情况下,任务类别中会显示一个JumpItem。 或者,可以为 <
可以通过设置ShowRecentCategory和ShowFrequentCategory属性来指定是否显示JumpList标准“最近”和“频繁”类别。 这些类别的内容由 Windows shell 管理。 由于这些类别可能包含很多相同的数据,因此通常会在两 JumpList者中显示一个或另一个数据。 如果通过公共文件对话框打开最近项,或者用于通过文件类型关联打开应用程序,则Windows会自动管理这些项。 通过跳转列表访问项时,可以通过调用 AddToRecentCategory 方法通知 Windows shell 将项添加到 Recent 类别。
将跳转列表应用于 Windows Shell
不能直接访问 shell 的跳转列表或将其内容读取到类中 JumpList 。 相反,JumpList 类提供了一个跳转列表的表示形式,你可以使用跳转列表,然后应用于Windows shell。 通常在首次运行应用程序时创建 JumpList 并设置一次。 但是,可以在运行时修改或替换 JumpList 。
设置 JumpList 属性后,必须先将 JumpList 应用于 Windows shell,然后才能将其内容显示在任务栏跳转列表中。 当首次附加到应用程序时 JumpList (在 XAML 中或调用 SetJumpList 该方法时)会自动完成此操作。 如果在运行时修改 JumpList的内容,则必须调用 Apply 方法,将其当前内容应用于 Windows shell。
在 XAML 中设置跳转列表
A JumpList 不会自动附加到对象 Application 。 使用附加的属性语法将对象 JumpList 附加到 Application XAML 中的对象。 该 JumpList 类实现接口 ISupportInitialize 以支持 XAML 声明 JumpList。 如果在 XAML 中声明了 JumpList并附加到当前 Application,则初始化 JumpList 时,它将自动应用于 Windows shell。
在代码中设置和修改跳转列表
通过调用静态SetJumpList方法,将对象JumpList附加到Application代码中的对象。 这还将 JumpList 应用于 Windows shell。
若要在运行时修改, JumpList 请调用 GetJumpList 该方法以获取 JumpList 当前附加到 an 的方法 Application。 修改 JumpList 的属性后,必须调用 Apply 方法,以将更改应用于 Windows shell。
注释
通常创建附加到 Application 并应用于 Windows shell 的 JumpList。 但是,可以创建多个 JumpList 对象。 一次只能将一个 JumpList应用于 Windows shell,一次只能将一个 JumpList 与 Application 相关联。 .NET Framework 不需要这些JumpList相同。
注释
此类包含应用于所有成员的类级别的链接需求。 当即时调用方没有完全信任权限时,将引发 A 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 |
当用户从列表中删除之前在跳转列表中的跳转项时发生。 |