Posted by: Zeeshan Amjad | March 10, 2010

Using Radio Button in Status Bar


We already saw one example of using Radio button in tree control here. Now we are going to use the radio button in Status bar. Inserting radio button in Status bar is very similar to use in any other control. Here is a piece of XAML code to demonstrate this.

  1: <StatusBar DockPanel.Dock="Bottom">
  2: 	<RadioButton Name="optRed" Content="Red" Click="optRed_Click" />
  3: 	<RadioButton Name="optBlue" Content="Blue" Click="optBlue_Click" />
  4: 	<RadioButton Name="optGreen" Content="Green" Click="optGreen_Click" />
  5: 	<RadioButton Name="optYello" Content="Yellow" Click="optYello_Click" />
  6: </StatusBar>
  7: 

Here we define the name of all radio button because we are going to write event handler to keep this program simple. Latter we can enhance it to do the command binding. Here is complete XAML code of this program.

  1: <Window x:Class="WpfStatusBar.Window1"
  2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:     Title="Status Bar" Height="300" Width="300">
  5:     <DockPanel>
  6:         <StatusBar DockPanel.Dock="Bottom">
  7:             <RadioButton Name="optRed" Content="Red" Click="optRed_Click" />
  8:             <RadioButton Name="optBlue" Content="Blue" Click="optBlue_Click" />
  9:             <RadioButton Name="optGreen" Content="Green" Click="optGreen_Click" />
 10:             <RadioButton Name="optYello" Content="Yellow" Click="optYello_Click" />
 11:         </StatusBar>
 12:         <Grid>
 13:             <Grid.RowDefinitions>
 14:                 <RowDefinition/>
 15:                 <RowDefinition/>
 16:             </Grid.RowDefinitions>
 17:             <Grid.ColumnDefinitions>
 18:                 <ColumnDefinition/>
 19:                 <ColumnDefinition/>
 20:             </Grid.ColumnDefinitions>
 21:             
 22:             <Border Grid.Column="0" Grid.Row="0" Margin="5" CornerRadius="10"
 23:                     Name="border1" Background="Wheat"/>
 24:             <Border Grid.Column="1" Grid.Row="0" Margin="5" CornerRadius="10"
 25:                     Name="border2" Background="Wheat"/>
 26:             <Border Grid.Column="0" Grid.Row="1" Margin="5" CornerRadius="10"
 27:                     Name="border3" Background="Wheat"/>
 28:             <Border Grid.Column="1" Grid.Row="1" Margin="5" CornerRadius="10"
 29:                     Name="border4" Background="Wheat"/>
 30:         </Grid>
 31:     </DockPanel>
 32: </Window>
 33: 

Here is complete C# code of this program including the event handler.

  1: using System;
  2: using System.Collections.Generic;
  3: using System.Linq;
  4: using System.Text;
  5: using System.Windows;
  6: using System.Windows.Controls;
  7: using System.Windows.Data;
  8: using System.Windows.Documents;
  9: using System.Windows.Input;
 10: using System.Windows.Media;
 11: using System.Windows.Media.Imaging;
 12: using System.Windows.Navigation;
 13: using System.Windows.Shapes;
 14: 
 15: namespace WpfStatusBar
 16: {
 17:     /// <summary>
 18:     /// Interaction logic for Window1.xaml
 19:     /// </summary>
 20:     public partial class Window1 : Window
 21:     {
 22:         public Window1()
 23:         {
 24:             InitializeComponent();
 25:         }
 26: 
 27:         private void optRed_Click(object sender, RoutedEventArgs e)
 28:         {
 29:             border1.Background = Brushes.Red;
 30:             border2.Background = Brushes.Red;
 31:             border3.Background = Brushes.Red;
 32:             border4.Background = Brushes.Red;
 33:         }
 34: 
 35:         private void optBlue_Click(object sender, RoutedEventArgs e)
 36:         {
 37:             border1.Background = Brushes.Blue;
 38:             border2.Background = Brushes.Blue;
 39:             border3.Background = Brushes.Blue;
 40:             border4.Background = Brushes.Blue;
 41:         }
 42: 
 43:         private void optGreen_Click(object sender, RoutedEventArgs e)
 44:         {
 45:             border1.Background = Brushes.Green;
 46:             border2.Background = Brushes.Green;
 47:             border3.Background = Brushes.Green;
 48:             border4.Background = Brushes.Green;
 49:         }
 50: 
 51:         private void optYello_Click(object sender, RoutedEventArgs e)
 52:         {
 53:             border1.Background = Brushes.Yellow;
 54:             border2.Background = Brushes.Yellow;
 55:             border3.Background = Brushes.Yellow;
 56:             border4.Background = Brushes.Yellow;
 57:         }
 58:     }
 59: }
 60: 

Here is the output of the program when it runs.

StatusBarRadioOutput_01

But if we click any of the button then the background of border control will change accordingly. Here is the output of the program when we click on Blue radio button.

StatusBarRadioOutput_02

Advertisements

Responses

  1. […] the Status Bar We already saw the example of using Radion button inside the status bar here and here. Now we are going to use Progress bar inside the status bar. The first difference we […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: