Click here to Skip to main content
15,888,610 members
Articles / Desktop Programming / XAML

Anatomy of the Windows 7 taskbar - Progress

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
26 Oct 2010CPOL 11.2K   7   1
Anatomy of the Windows 7 taskbar - Progress

Ever noticed the subtle progress overlay while downloading something from the internet? With Windows 7’s new taskbar, applications can visually display their progress on the taskbar!

We first need to set the mode:

C#
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);

The Windows 7 taskbar has 5 possible states:

  • NoProgress - No progress is displayed
  • Indeterminate - The progress is indeterminate (marquee)
  • Normal - Normal progress is displayed
  • Error - An error occurred (red)
  • Paused - The operation is paused (yellow)

If the state is changed to Normal, then you can also set the value:

C#
TaskbarManager.Instance.SetProgressValue(50, 100);

Easy? Isn't it?

What would a post be without trying to make it just a little easier for the WPF developers? I also created an attached property that auto-magically links a WPF ProgressBar to the Windows 7 taskbar…

Here is my very simple demo:

XML
<Window x:Class="ProgressDemo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:="clr-namespace:ProgressDemo"
    Title="ProgressDemo" Height="100" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Slider Minimum="0" Maximum="100" x:Name="source" Grid.Row="0" />
        <ProgressBar Minimum="0" Maximum="100" Grid.Row="1" Height="20"
             Value="{Binding ElementName=source, Path=Value}" 
             local:Win7.ShowProgressInTaskbar="True" />
    </Grid>
</Window>

As you can see from this XAML, I created a Slider and bound it to the ProgressBar. To make the ProgressBar auto-magically update the Windows 7 taskbar, all we need to do is set the ShowProgressInTaskbar=”True”!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
KBeigel2-Nov-10 3:10
KBeigel2-Nov-10 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.