Menus,Status and Toolbar controls in WPF
Menus:
The Menu and the MenuItem classes represent a menu in wpf
Namespace : System.Windows.Controls.Menu
For HotKeys use '_' in menu strings
Designer Code:
<!--Window1.XAML-->
<Menu Height="22" Name="menu1" Width="300" Margin="10, 10, 5, 5"
HorizontalAlignment="Left" VerticalAlignment="Top" Background="Red">
<MenuItem Header="_One">
<MenuItem Header="_Two" IsCheckable="true"
Click="MenuItem_Click"/>
<MenuItem Header="_Three" IsCheckable="true"/>
</MenuItem>
</Menu>
Code Behind:
// Window1.xaml.cs
private void MenuItem_Click(object sender,
RoutedEventArgs e)
{
MessageBox.Show("From menu two");
}
//Adding menus from code
Menu mainMenu = new Menu();
mainMenu.Height = 30;
mainMenu.Width = 200;
MenuItem item1 = new MenuItem();
item1.Width = 100;
item1.Header = "one";
mainMenu.Items.Add(item1);
For seperator use <Separator /> tag.
Tooltips to Menus:
<MenuItem Header="_Two" IsCheckable="true" Click="MenuItem_Click">
<MenuItem.ToolTip>
<ToolTip>
Sample Tool tip
</ToolTip>
</MenuItem.ToolTip>
</MenuItem>
Checkboxes and shortcut keys in Menus:
<MenuItem Header="_Two" IsCheckable="true" InputGestureText="Ctrl+T">
</MenuItem>
Icons in Menus:
<MenuItem Header="_Two" IsCheckable="true" InputGestureText="Ctrl+T">
<MenuItem.Icon>
<Image Source="win2wpf.jpg" Width="20" Height="20" />
</MenuItem.Icon>
</MenuItem>
background images in menuitems:
<MenuItem.Background>
<ImageBrush ImageSource="win2wpf.jpg" Stretch="Fill" />
</MenuItem.Background>
Styles in Menus:
<Menu Height="22" Name="menu1" Width="300" Margin="10, 10, 5, 5"
HorizontalAlignment="Left" VerticalAlignment="Top">
<Menu.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Yellow" Offset="0.528"/>
<GradientStop Color="#FF6A85D8" Offset="0.01"/>
<GradientStop Color="Blue" Offset="1"/>
<GradientStop Color="#FF202E7E" Offset="1"/>
</LinearGradientBrush>
</Menu.Background>
</Menu>
StatusBar:
The StatusBar and the StatusBarItem classes represent a StatusBar in wpf
Namespace : System.Windows.Controls.Primitives.StatusBar
Designer Code:
<!--Window1.XAML-->
<StatusBar x:Name="StatusBar" VerticalAlignment="Bottom" Height="30"
Background="Orange">
<StatusBarItem Name="sbi1">
<Label>Teststaus</Label>
</StatusBarItem>
<Separator/>
<StatusBarItem>
<CheckBox>TeststausTwo</CheckBox>
</StatusBarItem>
</StatusBar>
Code Behind:
// Window1.xaml.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
sbi1.Content = "hello";
}
//Adding StatusBarItem from code
StatusBar sb = new StatusBar();
StatusBarItem item1 = new StatusBarItem();
item1.Width = 100;
Label lbl = new Label();
lbl.Content = "Hello";
item1.Content = lbl;
sb.Items.Add(item1);
Styles in StatusBar:
<StatusBar.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Yellow" Offset="0.528"/>
<GradientStop Color="#FF6A85D8" Offset="0.01"/>
<GradientStop Color="Blue" Offset="1"/>
<GradientStop Color="#FF202E7E" Offset="1"/>
</LinearGradientBrush>
</StatusBar.Background>
Progressbar in StatusBar:
<StatusBarItem>
<ProgressBar Value="30" Width="50" Height="18"
HorizontalAlignment="Right" Background="Red"/>
</StatusBarItem>
Toolbar:
The Toolbar a classe represent a StatusBar in wpf
Namespace : System.Windows.Controls.Primitives.Toolbar
Designer Code:
<!--Window1.XAML-->
<ToolBar x:Name="StatusBar" VerticalAlignment="Bottom" Height="30"
Margin="1,0,-1,225">
<Label>Toollabel</Label>
<Separator/>
<Button Name="btn1" Click="btn1_Click">Buttontest</Button>
<Separator/>
<Image Source="\Images\win2wpf.JPG"></Image>
</ToolBar>
Code Behind:
// Window1.xaml.cs
private void btn1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("From Toolbar");
}
Styles in Toolbar:
<ToolBar.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Yellow" Offset="0.528"/>
<GradientStop Color="#FF6A85D8" Offset="0.01"/>
<GradientStop Color="Blue" Offset="1"/>
<GradientStop Color="#FF202E7E" Offset="1"/>
</LinearGradientBrush>
</ToolBar.Background>