WPF StatusBar Using VB.NET

StatusBar is a WPF control we used namespace System.Windows.Controls.Primitives.StatusBar for this. And its exists in PresentationFramework.dll assembly.
  • 3742

Introduction

Here I am talking about the StatusBar control which can contain a collection of objects of any type (such as Panel, string etc). StatusBar is a WPF control we used namespace System.Windows.Controls.Primitives.StatusBar for this. And its exists in PresentationFramework.dll assembly. StatusBar control is very useful control in WPF. StatusBar control Represents a control that displays items and information in a horizontal bar in an application window. We can divide the elements in a StatusBar into groups that contain related items, by using Separator controls. Here is a WPF StatusBar which represents a control  that shows elements and information in a horizontal bar in an application window. The elements  in a StatusBar can display text, graphics, or other complex content. Items in a StatusBar are defined as StatusBarItem objects. XAML code for StatusBar will look like this in code window.

XAML code

<StatusBar>

  Content

</StatusBar>

 

When we add a StatusBar in our page the code of Status Bar is 

<Window x:Class="MainWindow"
  
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
Title="MainWindow" Height="350" Width="525">
<
Grid>
<
StatusBar Height="61" HorizontalAlignment="Left" Margin="10,10,0,0" 
  Name
="StatusBar1" VerticalAlignment="Top" Width="481" />
<
Label Content="Status Bar" Height="28" HorizontalAlignment="Left" 
  Margin
="10,10,0,0" Name="Label1" VerticalAlignment="Top" Width="150" />
</
Grid>
</
Window>

Output for this code will look this.

img1.png

Design Time 

When we design a StatusBar in our page it will look like on Main window. we have ProgressBar and a TextBlock, It means we have StatusBar Items. Code will add in XAML will look like this when we design these items in our page.

<Grid>
<
StatusBar Name="sbar" VerticalAlignment="Top" Background="DarkOrange" Height="48">
<
StatusBarItem>
<
ProgressBar Width="175" Height="25"Name="progressBar1">
<
ProgressBar.Triggers>
<
EventTrigger RoutedEvent="ProgressBar.Loaded">
<
BeginStoryboard>
<
Storyboard>
<
DoubleAnimation Storyboard.TargetName="progressBar1" Storyboard.TargetProperty="Value
 
From="0" To="100" Duration="0:0:5" 
 />
</
Storyboard>
</
BeginStoryboard>
</
EventTrigger>
</
ProgressBar.Triggers> 
</ProgressBar>
</
StatusBarItem>
<
Separator/>
<
StatusBarItem>
<
TextBlock> Ohh...Its Moving..!!</TextBlock>
</
StatusBarItem>
</
StatusBar>
<
Border BorderBrush="Blue" BorderThickness="5" Height="48" HorizontalAlignment="Left" 
Name
="Border1" VerticalAlignment="Top" Width="709" />
</
Grid>
</
Window>

There is a main window image at design time, It will look like this.

img2.png
 

When we run the above code output will show at run time.

img3.png

StatusBar with Image control

There is a image control which is used with StatusBar in this code. when we add a image at design time the code is in XAML.

<Image HorizontalAlignment="Left" Margin="0,54,0,0" Name="Image1" Stretch="Fill" 
  Width
="709" Source="/WpfApplication2;component/images/imag4.png" Height="366" 
  VerticalAlignment
="Top" />

We can create StatusBar with different controls. Here is a Status Bar which is used with ProgressBar,TextBlock,Border and Image control also. When we add items in StatusBar we used StatusBarItem tag. How ProgressBar moves at run time, We used triggers property in progressBar it
established directly on this Item, or in child Items. There is a XAML code this will show how it works.

<
Grid>
<
StatusBar Name="sbar" VerticalAlignment="Top" Background="DarkOrange" Height="48">
<
StatusBarItem>
<
ProgressBar Width="175" Height="25"Name="progressBar1">
<
ProgressBar.Triggers>
<
EventTrigger RoutedEvent="ProgressBar.Loaded">
<
BeginStoryboard>
<
Storyboard>
<
DoubleAnimation Storyboard.TargetName="progressBar1" Storyboard.TargetProperty="Value"
  
From="0" To="100" Duration="0:0:5"  />
</
Storyboard>
</
BeginStoryboard>
</
EventTrigger>
</
ProgressBar.Triggers>
</
ProgressBar>
</
StatusBarItem>
<
Separator/>
<
StatusBarItem>
<
TextBlock> Ohh...Its Moving..!!</TextBlock>
</
StatusBarItem>
</
StatusBar>
<
Border BorderBrush="Blue" BorderThickness="5" Height="48" HorizontalAlignment="Left" 
  Name
="Border1" VerticalAlignment="Top" Width="709" />
<
Image HorizontalAlignment="Left" Margin="0,54,0,0" Name="Image1" Stretch="Fill" Width="709" 
  Source
="/WpfApplication2;component/images/imag4.png" Height="366" VerticalAlignment="Top" />
</
Grid>
</
Window>
 

The output for this code will be at run time.

img4.png

Properties

There are several properties which are used with StatusBar. some are very useful when we create a StatusBar.

Background- set or get a brush that defines the background of a control.

Clip - set or get the geometry used to define the outline of the contents of an element. It is a dependency property. 

BorderBrush - set or get a brush that defines the border background of a control. 

FlowDirection - set or get the direction that text and other user interface elements flow within any parent element that controls their layout.

Focusable - set or get a value that shows whether the element can receive focus. Its is a dependency property. 

HandlesScrolling - get a value that shows whether a control supports scrolling. 

Triggers - Get the collection of triggers established directly on this Item, or in child Items.

I hope this article will help you to create StatusBar with different controls.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.