Partager via


StatusBar Overview

A StatusBar is a horizontal area at the bottom of an application window where an application can display various types of status information. You can divide a StatusBar into sections so that it can better display more than one type of information. This topic introduces the StatusBar control and shows how to create one.

This topic contains the following sections.

  • What Is a StatusBar?
  • Creating a StatusBar
  • Styling a StatusBar
  • Handling Events
  • Related Topics

What Is a StatusBar?

The StatusBar is a visual indicator of the operational status of an application and its components. A StatusBar control consists of a series of StatusBarItem controls that can display text, graphics, and other content. The control can group items to show relational similarities and can separate groups of items by using Separator controls.

The following illustration shows an example of a StatusBar.

Status bar

Creating a StatusBar

The following example shows how to define a StatusBar by using Extensible Application Markup Language (XAML) and how to add a ProgressBar by using code.

<StatusBar Name="sbar" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" 
           VerticalAlignment="Bottom" Background="Beige" > 
     <StatusBarItem>
       <TextBlock>Ready</TextBlock>
     </StatusBarItem>
     <StatusBarItem>
       <Separator Style="{StaticResource StatusBarSeparatorStyle}"/>
     </StatusBarItem>
</StatusBar>
private void MakeProgressBar(object sender, RoutedEventArgs e)
{
  sbar.Items.Clear();
  TextBlock txtb = new TextBlock();
  txtb.Text = "Progress of download.";
  sbar.Items.Add(txtb);
  ProgressBar progressbar = new ProgressBar();
  Duration duration = new Duration(TimeSpan.FromSeconds(10));
  DoubleAnimation doubleanimation = 
                             new DoubleAnimation(100.0, duration);
  progressbar.BeginAnimation(ProgressBar.ValueProperty, 
                             doubleanimation);
  ToolTip ttprogbar = new ToolTip();
  ttprogbar.Content = "Shows the progress of a download.";
  progressbar.ToolTip = (ttprogbar);
  sbar.Items.Add(progressbar);
} 

For the complete sample, see StatusBar Sample.

Styling a StatusBar

You can apply a Style to a group of related StatusBarItem objects by applying a GroupStyle. To show divisions between groups of related StatusBarItem objects, add a Separator control to the StatusBarItem collection. You can also set the style for the Separator by specifying a SeparatorStyleKey.

The following example shows how to add Items that are separated by a Separator in a StatusBar that is named sbar.

Image helpImage = new Image();
 helpImage.Width = 16;
 helpImage.Height = 16;
 BitmapImage bi = new BitmapImage();
 bi.BeginInit();
 bi.UriSource = new Uri(@"pack://application:,,,/images/help.bmp");
 bi.EndInit();
 helpImage.Source = bi;
 ToolTip ttp = new ToolTip();
 ttp.Content = "HELP";
 helpImage.ToolTip = (ttp);
 sbar.Items.Add(helpImage);

 Separator sp = new Separator();
 sp.Style = (Style)FindResource("StatusBarSeparatorStyle");
 sbar.Items.Add(sp);
 
 Image printImage = new Image();
 printImage.Width = 16;
 printImage.Height = 16;
 BitmapImage bi_print = new BitmapImage();
 bi_print.BeginInit();
 bi_print.UriSource = new Uri(@"pack://application:,,,/images/print.bmp");
 bi_print.EndInit();
 printImage.Source = bi_print;
 ToolTip ttp_print = new ToolTip();
 ttp.Content = "Sent to printer.";
 printImage.ToolTip = (ttp_print);
 sbar.Items.Add(printImage);

If you do not set the Width on a StatusBarItem, its content determines its size.

To place a StatusBar at the bottom of your application window, set the VerticalAlignment to Bottom. To define horizontal placement, set the HorizontalAlignment property.

Handling Events

A StatusBar and its StatusBarItem objects cannot receive keyboard focus. However, a StatusBarItem object can receive mouse events that occur when the mouse pauses over it.

See Also

Tasks

How to: Create a StatusBar

Reference

StatusBar
StatusBarItem