TaskbarItemInfo 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表工作列縮圖顯示方式的資訊。
public ref class TaskbarItemInfo sealed : System::Windows::Freezable
public sealed class TaskbarItemInfo : System.Windows.Freezable
type TaskbarItemInfo = class
inherit Freezable
Public NotInheritable Class TaskbarItemInfo
Inherits Freezable
- 繼承
範例
以下範例說明如何建立 TaskbarItemInfo in 標記。 裡面 TaskbarItemInfo 包含一組 ThumbButtonInfo 物件,提供從工作列項目中存取播放和停止指令的權限。
<Window.TaskbarItemInfo>
<TaskbarItemInfo x:Name="taskBarItemInfo1"
Overlay="{StaticResource ResourceKey=StopImage}"
ThumbnailClipMargin="80,0,80,140"
Description="Taskbar Item Info Sample">
<TaskbarItemInfo.ThumbButtonInfos>
<ThumbButtonInfoCollection>
<ThumbButtonInfo
DismissWhenClicked="False"
Command="MediaCommands.Play"
CommandTarget="{Binding ElementName=btnPlay}"
Description="Play"
ImageSource="{StaticResource ResourceKey=PlayImage}"/>
<ThumbButtonInfo
DismissWhenClicked="True"
Command="MediaCommands.Stop"
CommandTarget="{Binding ElementName=btnStop}"
Description="Stop"
ImageSource="{StaticResource ResourceKey=StopImage}"/>
</ThumbButtonInfoCollection>
</TaskbarItemInfo.ThumbButtonInfos>
</TaskbarItemInfo>
</Window.TaskbarItemInfo>
以下標記與程式碼展示了前述範例的完整上下文。 應用程式使用 a BackgroundWorker 從 0 數到 100,並在使用者介面中顯示進度。 任務可以從工作列預覽中開始或停止。 進度會顯示在工作列按鈕中。
<Window x:Class="Shell_TaskbarItemSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<Window.Resources>
<DrawingImage x:Key="PlayImage">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="Green" Geometry="F1 M 50,25L 0,0L 0,50L 50,25 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
<DrawingImage x:Key="StopImage">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="Gray" Geometry="F1 M 0,0L 50,0L 50,50L 0,50L 0,0 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="MediaCommands.Play"
Executed="StartCommand_Executed"
CanExecute="StartCommand_CanExecute"/>
<CommandBinding Command="MediaCommands.Stop"
Executed="StopCommand_Executed"
CanExecute="StopCommand_CanExecute"/>
</Window.CommandBindings>
<Window.TaskbarItemInfo>
<TaskbarItemInfo x:Name="taskBarItemInfo1"
Overlay="{StaticResource ResourceKey=StopImage}"
ThumbnailClipMargin="80,0,80,140"
Description="Taskbar Item Info Sample">
<TaskbarItemInfo.ThumbButtonInfos>
<ThumbButtonInfoCollection>
<ThumbButtonInfo
DismissWhenClicked="False"
Command="MediaCommands.Play"
CommandTarget="{Binding ElementName=btnPlay}"
Description="Play"
ImageSource="{StaticResource ResourceKey=PlayImage}"/>
<ThumbButtonInfo
DismissWhenClicked="True"
Command="MediaCommands.Stop"
CommandTarget="{Binding ElementName=btnStop}"
Description="Stop"
ImageSource="{StaticResource ResourceKey=StopImage}"/>
</ThumbButtonInfoCollection>
</TaskbarItemInfo.ThumbButtonInfos>
</TaskbarItemInfo>
</Window.TaskbarItemInfo>
<Grid>
<StackPanel>
<TextBlock x:Name="tbCount" FontSize="72" HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnPlay" Content="Play" Command="MediaCommands.Play" />
<Button x:Name="btnStop" Content="Stop" Command="MediaCommands.Stop" />
</StackPanel>
</StackPanel>
</Grid>
</Window>
// MainWindow.xaml.cs
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shell;
namespace Shell_TaskbarItemSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private BackgroundWorker _backgroundWorker = new BackgroundWorker();
public MainWindow()
{
InitializeComponent();
// Set up the BackgroundWorker.
this._backgroundWorker.WorkerReportsProgress = true;
this._backgroundWorker.WorkerSupportsCancellation = true;
this._backgroundWorker.DoWork += new DoWorkEventHandler(bw_DoWork);
this._backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
this._backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
}
private void StartCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
e.Handled = true;
}
private void StartCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
if (!this._backgroundWorker.IsBusy)
{
this._backgroundWorker.RunWorkerAsync();
// When the task is started, change the ProgressState and Overlay
// of the taskbar item to indicate an active task.
this.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.Normal;
this.taskBarItemInfo1.Overlay = (DrawingImage)this.FindResource("PlayImage");
}
e.Handled = true;
}
private void StopCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = this._backgroundWorker.WorkerSupportsCancellation;
e.Handled = true;
}
private void StopCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
this._backgroundWorker.CancelAsync();
e.Handled = true;
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// When the task ends, change the ProgressState and Overlay
// of the taskbar item to indicate a stopped task.
if (e.Cancelled)
{
// The task was stopped by the user. Show the progress indicator
// in the paused state.
this.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.Paused;
}
else if (e.Error != null)
{
// The task ended with an error. Show the progress indicator
// in the error state.
this.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.Error;
}
else
{
// The task completed normally. Remove the progress indicator.
this.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.None;
}
// In all cases, show the 'Stopped' overlay.
this.taskBarItemInfo1.Overlay = (DrawingImage)this.FindResource("StopImage");
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.tbCount.Text = e.ProgressPercentage.ToString();
// Update the value of the task bar progress indicator.
this.taskBarItemInfo1.ProgressValue = (double)e.ProgressPercentage / 100;
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker _worker = sender as BackgroundWorker;
if (_worker != null)
{
for (int i = 1; i <= 100; i++)
{
if (_worker.CancellationPending)
{
e.Cancel = true;
break;
}
else
{
System.Threading.Thread.Sleep(25);
_worker.ReportProgress(i);
}
}
}
}
}
}
' MainWindow.xaml.vb
Imports System.ComponentModel
Imports System.Windows.Shell
Class MainWindow
Private _backgroundWorker As New BackgroundWorker
Public Sub New()
InitializeComponent()
' Set up the BackgroundWorker
Me._backgroundWorker.WorkerReportsProgress = True
Me._backgroundWorker.WorkerSupportsCancellation = True
AddHandler Me._backgroundWorker.DoWork, AddressOf bw_DoWork
AddHandler Me._backgroundWorker.ProgressChanged, AddressOf bw_ProgressChanged
AddHandler Me._backgroundWorker.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted
End Sub
Private Sub StartCommand_CanExecute(ByVal sender As System.Object, ByVal e As System.Windows.Input.CanExecuteRoutedEventArgs)
e.CanExecute = True
e.Handled = True
End Sub
Private Sub StartCommand_Executed(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
If Me._backgroundWorker.IsBusy = False Then
Me._backgroundWorker.RunWorkerAsync()
' When the task is started, change the ProgressState and Overlay
' of the taskbar item to indicate an active task.
Me.taskBarItemInfo1.ProgressState = Shell.TaskbarItemProgressState.Normal
Me.taskBarItemInfo1.Overlay = Me.FindResource("PlayImage")
End If
e.Handled = True
End Sub
Private Sub StopCommand_CanExecute(ByVal sender As System.Object, ByVal e As System.Windows.Input.CanExecuteRoutedEventArgs)
e.CanExecute = Me._backgroundWorker.WorkerSupportsCancellation
e.Handled = True
End Sub
Private Sub StopCommand_Executed(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
Me._backgroundWorker.CancelAsync()
e.Handled = True
End Sub
Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
' When the task ends, change the ProgressState and Overlay
' of the taskbar item to indicate a stopped task.
If e.Cancelled = True Then
' The task was stopped by the user. Show the progress indicator
' in the paused state.
Me.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.Paused
ElseIf e.Error IsNot Nothing Then
' The task ended with an error. Show the progress indicator
' in the error state.
Me.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.Error
Else
' The task completed normally. Remove the progress indicator.
Me.taskBarItemInfo1.ProgressState = TaskbarItemProgressState.None
' In all cases, show the 'Stopped' overlay.
Me.taskBarItemInfo1.Overlay = Me.FindResource("StopImage")
End If
End Sub
Private Sub bw_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
Me.tbCount.Text = e.ProgressPercentage.ToString()
' Update the value of the task bar progress indicator.
Me.taskBarItemInfo1.ProgressValue = e.ProgressPercentage / 100
End Sub
Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim _worker As BackgroundWorker = CType(sender, BackgroundWorker)
If _worker IsNot Nothing Then
For i As Integer = 1 To 100 Step 1
If _worker.CancellationPending = True Then
e.Cancel = True
Return
Else
System.Threading.Thread.Sleep(25)
_worker.ReportProgress(i)
End If
Next
End If
End Sub
End Class
備註
該 TaskbarItemInfo 類別提供一個 Windows 7 工作列功能的受管理包裝器。 欲了解更多關於 Windows shell 與原生工作列 API 的資訊,請參閱 工作列擴充功能。 TaskbarItemInfo 是作為依賴性質暴露 Window.TaskbarItemInfo 於 Window的。
Windows 7 工作列提供了增強功能,讓你能利用工作列項目向使用者傳達狀態,並在視窗最小化或隱藏時暴露常見任務。 該類別所暴露 TaskbarItemInfo 的功能在 Windows 7 之前的版本中無法使用。 使用此 TaskbarItemInfo 類別的應用程式仍可在較早期版本的 Windows 中執行;但這些工作列增強功能在早期版本中無法使用。
在 Windows 7 中,根據使用者設定,部分工作列功能可能無法使用。 例如,若關閉 Windows Aero 或應用程式以提升權限啟動,工作列功能將無法使用。 你的應用程式應該提供其他與使用者互動的方式,不必依賴 Windows 7 中增強的任務列功能。
通知區位於工作列最右側的程式圖示,通常用來向使用者傳達應用程式狀態。 預設情況下,Windows 7 的工作列會隱藏通知區的程式圖示。 不過,你可以設定 Overlay 該屬性,在工作列按鈕中加入圖片以傳達狀態,例如訊息應用程式中的線上狀態。 覆蓋圖片讓使用者即使看不到通知區的程式圖示,也能看到應用程式狀態。 你也可以在 ProgressState 工作列按鈕中設定 和 ProgressValue 屬性來顯示執行任務的進度。
當你將滑鼠指標移到工作列按鈕上時,Windows 7 工作列會顯示應用程式的縮圖。 預設情況下,整個應用程式視窗都會顯示。 你可以透過設定 ThumbnailClipMargin 屬性,指定視窗的特定區域要在縮圖中顯示。 你也可以指定一個會在工作列縮圖上方的提示中顯示的。Description 即使縮圖因使用者設定無法顯示,提示仍會顯示。
你可以在工作列縮圖中新增按鈕,讓使用者能存取常見任務,而不必切換到應用程式視窗。 例如,視窗媒體播放器提供播放、暫停、快轉和返回按鈕,讓你在應用程式最小化時,從工作列縮圖控制媒體播放。 工作列縮圖中的按鈕以物件表示 ThumbButtonInfo ,並包含在 ThumbButtonInfos 集合中。
以下圖示展示了 Windows 7 工作列的增強功能。
Windows 工作列增強功能
建構函式
| 名稱 | Description |
|---|---|
| TaskbarItemInfo() |
初始化 TaskbarItemInfo 類別的新執行個體。 |
欄位
| 名稱 | Description |
|---|---|
| DescriptionProperty |
識別 Description 依賴性質。 |
| OverlayProperty |
識別 Overlay 依賴性質。 |
| ProgressStateProperty |
識別 ProgressState 依賴性質。 |
| ProgressValueProperty |
識別 ProgressValue 依賴性質。 |
| ThumbButtonInfosProperty |
識別 ThumbButtonInfos 依賴性質。 |
| ThumbnailClipMarginProperty |
識別 ThumbnailClipMargin 依賴性質。 |
屬性
| 名稱 | Description |
|---|---|
| CanFreeze |
會得到一個值,表示該物件是否能被設定為不可修改。 (繼承來源 Freezable) |
| DependencyObjectType |
會取得 DependencyObjectType 包裹此實例 CLR 類型的 。 (繼承來源 DependencyObject) |
| Description |
取得或設定任務列項目提示的文字。 |
| Dispatcher |
了解 Dispatcher 這與此 DispatcherObject 有關。 (繼承來源 DispatcherObject) |
| IsFrozen |
會得到一個值,表示該物件目前是否可修改。 (繼承來源 Freezable) |
| IsSealed |
會獲得一個值,表示該實例目前是否封存(唯讀)。 (繼承來源 DependencyObject) |
| Overlay |
取得或設定顯示在工作列按鈕中程式圖示上的圖片。 |
| ProgressState |
會取得或設定一個值,指示進度指示器在工作列按鈕中如何顯示。 |
| ProgressValue |
會取得或設定一個值,顯示工作列按鈕中進度指示器的滿載程度。 |
| ThumbButtonInfos |
取得或設定與 Window相關聯的物件集合ThumbButtonInfo。 |
| ThumbnailClipMargin |
取得或設定一個值,指定應用程式視窗客戶端區域中工作列縮圖中顯示的部分。 |
方法
事件
| 名稱 | Description |
|---|---|
| Changed |
當 Freezable 它所包含的物件被修改時,會發生這種情況。 (繼承來源 Freezable) |