MenuItem Commands And Events : Menu « Windows Presentation Foundation « VB.Net






MenuItem Commands And Events

MenuItem Commands And Events
    

<Window x:Class="MenuItemCommands.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MenuItem Commands and Events Sample" Height="300" Width="300">
  <StackPanel>
    <Menu>
      <MenuItem Header="_Edit">
        <MenuItem Command="ApplicationCommands.Copy"/>
        <MenuItem Command="ApplicationCommands.Cut"/>
        <MenuItem Command="ApplicationCommands.Paste"/>
      </MenuItem>
      <MenuItem Header="_Font">
        <MenuItem Header="_Bold" IsCheckable="True" Checked="Bold_Checked" Unchecked="Bold_Unchecked"/>
        <MenuItem Header="_Italic" IsCheckable="True" Checked="Italic_Checked" Unchecked="Italic_Unchecked"/>
        <Separator/>
        <MenuItem Header="I_ncrease Font Size" Click="IncreaseFont_Click"/>
        <MenuItem Header="_Decrease Font Size" Click="DecreaseFont_Click"/>
      </MenuItem>
    </Menu>
    <TextBox Name="textBox1" TextWrapping="Wrap" Margin="2">
      this is a test
    </TextBox>
  </StackPanel>
</Window>
//File:Window.xaml.vb

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes


Namespace MenuItemCommands
  Public Partial Class Window1
    Inherits System.Windows.Window
    Public Sub New()
      InitializeComponent()
    End Sub
    Private Sub Bold_Checked(sender As Object, e As RoutedEventArgs)
      textBox1.FontWeight = FontWeights.Bold
    End Sub

    Private Sub Bold_Unchecked(sender As Object, e As RoutedEventArgs)
      textBox1.FontWeight = FontWeights.Normal
    End Sub
    Private Sub Italic_Checked(sender As Object, e As RoutedEventArgs)
      textBox1.FontStyle = FontStyles.Italic
    End Sub

    Private Sub Italic_Unchecked(sender As Object, e As RoutedEventArgs)
      textBox1.FontStyle = FontStyles.Normal
    End Sub

    Private Sub IncreaseFont_Click(sender As Object, e As RoutedEventArgs)
      textBox1.FontSize += 2
    End Sub

    Private Sub DecreaseFont_Click(sender As Object, e As RoutedEventArgs)
      textBox1.FontSize -= 2
    End Sub
  End Class
End Namespace

   
    
    
    
  








Related examples in the same category

1.Mixed MenusMixed Menus
2.Sidebar MenuSidebar Menu
3.Put a Menu and toolbar on the top of a DockPanelPut a Menu and toolbar on the top of a DockPanel
4.Nesting content inside MenuItem.HeaderNesting content inside MenuItem.Header
5.Multiple command targetsMultiple command targets
6.Commands with a menu and text boxCommands with a menu and text box
7.Set Access key for Menu with underscoreSet Access key for Menu with underscore
8.Menu and MenuItemMenu and MenuItem
9.Display a Context Menu with OpacityDisplay a Context Menu with Opacity
10.MenuBar and ToolBarMenuBar and ToolBar
11.Add Menu to NavigationWindow ContentAdd Menu to NavigationWindow Content
12.Menu item action handlerMenu item action handler