共用方式為


TaskbarItemInfo 類別

定義

代表工作列縮圖顯示方式的資訊。

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.TaskbarItemInfoWindow的。

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
CheckAccess()

判斷呼叫執行緒是否能存取此 DispatcherObject

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清算房產的當地價值。 要清除的屬性由識別 DependencyProperty 碼指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只讀屬性的局部值。 要清除的屬性由 DependencyPropertyKey指定。

(繼承來源 DependencyObject)
Clone()

建立可修改的克隆 Freezable,產生物件值的深度複製。 當複製物件的依賴屬性時,此方法會複製表達式(可能已無法解析),但不會複製動畫或其當前值。

(繼承來源 Freezable)
CloneCore(Freezable)

使用基礎(非動畫)屬性值,將實例複製為指定的 Freezable 複製(深度複製)。

(繼承來源 Freezable)
CloneCurrentValue()

使用目前的值建立可修改的複製品(深度複製)。Freezable

(繼承來源 Freezable)
CloneCurrentValueCore(Freezable)

利用目前屬性值,讓實例成為可修改的複製(深度複製)。Freezable

(繼承來源 Freezable)
CoerceValue(DependencyProperty)

強制設定指定的依賴性質值。 這是透過在屬性CoerceValueCallback中指定的依賴屬性元資料中,呼叫 的依賴屬性中的任何DependencyObject函式來達成的。

(繼承來源 DependencyObject)
CreateInstance()

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

(繼承來源 Freezable)
CreateInstanceCore()

當在導出類別中實作時,會建立該 Freezable 衍生類別的新實例。

(繼承來源 Freezable)
Equals(Object)

判斷所給的 DependencyObject 是否等同於電流 DependencyObject

(繼承來源 DependencyObject)
Freeze()

使目前物件無法修改,並將其 IsFrozen 屬性設為 true

(繼承來源 Freezable)
FreezeCore(Boolean)

使 Freezable 物件無法被修改,或測試是否能被修改。

(繼承來源 Freezable)
GetAsFrozen()

使用基礎(非動畫)屬性值建立一個凍結的 Freezable。 由於複製是凍結的,任何凍結的子物件都會透過參考被複製。

(繼承來源 Freezable)
GetAsFrozenCore(Freezable)

讓實例成為指定條件 Freezable 的凍結複製,使用基礎(非動畫)屬性值。

(繼承來源 Freezable)
GetCurrentValueAsFrozen()

用目前屬性值建立一個凍結的副本 Freezable 。 由於複製是凍結的,任何凍結的子物件都會透過參考被複製。

(繼承來源 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

使當前實例成為指定 Freezable的凍結克隆。 如果物件有動畫相依屬性,則會複製其目前的動畫值。

(繼承來源 Freezable)
GetHashCode()

會得到一個 DependencyObject雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立專門的枚舉器,用以判斷哪些相依屬性在局部 DependencyObject設定值。

(繼承來源 DependencyObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

回傳此實例 DependencyObject上依賴屬性的當前有效值。

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性質的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
OnChanged()

當當前 Freezable 物件被修改時呼叫。

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

此成員支援 Windows Presentation Foundation(WPF)基礎架構,並非直接從您的程式碼中使用。

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

確保剛設定的資料成員建立 DependencyObjectType 適當的上下文指標。

(繼承來源 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

DependencyObject寫 的OnPropertyChanged(DependencyPropertyChangedEventArgs)實作,也在回應類型中變動的依賴屬性Freezable時呼叫任何Changed處理器。

(繼承來源 Freezable)
ReadLocalValue(DependencyProperty)

回傳依賴屬性的局部值(若存在)。

(繼承來源 DependencyObject)
ReadPreamble()

確保存取 Freezable 的是有效的執行緒。 繼 Freezable 承者必須在任何讀取非相依屬性資料成員的資料 API 開頭呼叫此方法。

(繼承來源 Freezable)
SetCurrentValue(DependencyProperty, Object)

設定依賴屬性的值,且不改變其值來源。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定依賴屬性的局部值,並由其依賴屬性識別碼指定。

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定只讀相依屬性的本地值,該值由 DependencyPropertyKey 相依屬性的識別碼指定。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

回傳一個值,指示序列化程序是否應該將所提供的相依屬性的值序列化。

(繼承來源 DependencyObject)
ToString()

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

(繼承來源 Object)
VerifyAccess()

強制呼叫執行緒能存取此 DispatcherObject

(繼承來源 DispatcherObject)
WritePostscript()

提升 Changed 事件並 Freezable 調用其 OnChanged() 方法。 衍生於 的 Freezable 類別應在任何修改未儲存為相依屬性的類別成員的 API 結尾呼叫此方法。

(繼承來源 Freezable)
WritePreamble()

驗證 未 Freezable 被凍結,且存取時正從有效的執行緒上下文中存取。 Freezable 繼承者應在任何寫入非相依屬性資料成員的 API 開頭呼叫此方法。

(繼承來源 Freezable)

事件

名稱 Description
Changed

Freezable 它所包含的物件被修改時,會發生這種情況。

(繼承來源 Freezable)

適用於