Using StatusBar in WPF

Introduction

This article describes the use a StatusBar. A StstusBar is used in many applications to report information about the progresss of operations or current state of the software. A status bar is usually a thin, horizontal strip at the bottom of a window. Sometimes it just shows simple text. For more complex programs,the status bar may be split into many sections containing text, glyphs, progress bars and interactive controls.

Background

Here I have used StatusBar Control to add a status bar to an application. The StatusBar inherits from the ItemsControl class, in other words you can add multiple child controls and text elements to the status bar.

Solution

The DockPanel is included to allow the StatusBar to be docked to the bottom of the screen. You could dock the StatusBar in other positions or use an alternative layout control. However, the DockPanel approach is probably the most common.
The StatusBar itself contains simple text  and the Label is included to show how other controls would be arranged within the DockPanel.

Procedure

Create a new WPF application project in Visual Studio, naming the project, "StatusBarDemo". Once loaded, replace the XAML in the main window with the code below:

Step 1

The DockPanel is included to allow the StatusBar to be docked to the bottom of the screen as in the following:
 

<Window x:Class="StatusBarDemo.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="StatusBar Demo"

        Width="250"

        Height="200">

 

    <DockPanel>

           <StatusBar DockPanel.Dock="Bottom">

            </StatusBar>

       <Label>StatusBar Example</Label>

  </DockPanel>

</Window>

 
Output 
 
On running the application you will get the following window:
 
st2 

 

Step 2

Add a control to the StatusBar.

A common use of a status bar is to show the progress of a task with a progress bar.  This can be done by simply adding a ProgressBar control within the StatusBar's XAML element.

<StatusBar DockPanel.Dock="Bottom">           

       <ProgressBar Width="100" Height="15" Value="67" />            

</StatusBar>

 
Output 
 
st4 

Step 3

Adding Multiple Controls.

Since the StatusBar type is a subclass of ItemsControl, you can add any number of child controls. These are displayed across the status bar in the order in which they are defined. For example,
you could combine the "Loading..." message & "67%" message and the progress indicator side by side with the following XAML:

 <StatusBar DockPanel.Dock="Bottom">

            Loading...

            <ProgressBar Width="100" Height="15" Value="67" />          

       67%

  </StatusBar>

 
Output 
 
st5 

Step 4

The following is a sample use of Separators.

<StatusBar DockPanel.Dock="Bottom">

            Loading...

            <Separator />

            <ProgressBar Width="100" Height="15" Value="67" />

            <Separator />

            67%

        </StatusBar>

        <Label>StatusBar Example</Label>

We can insert section boundaries by adding separator controls.

Output 
 
st6 

Separator controls can be used with several parents, including progress bars, list boxes, tool bars and menus. Although it is possible to modify the style of a Separator, you can use the Standard Style.
You will often see status bars with sections separated by a vertical line with a standard style.

A Label Control is included here to be shown on the Top-Left of the Screen showing the title of the application.

Step 5

Also, we will need to make the class file of this application with a xaml.cs extension that describes the interaction logic for MainWindow.xaml as in the following:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

 

namespace StatusBarDemo

{

   

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

        }

    }

}