MenuItem.Click Event

Occurs when a MenuItem is clicked.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
Public Event Click As RoutedEventHandler
'Usage
Dim instance As MenuItem 
Dim handler As RoutedEventHandler 

AddHandler instance.Click, handler
<object Click="RoutedEventHandler" .../>

Identifier field

ClickEvent

Routing strategy

Bubbling

Delegate

RoutedEventHandler

The Click event does not occur if the MenuItem has a submenu.

The following example creates a Menu to manipulate text in a TextBox. The Menu contains MenuItem objects that use the Command, IsCheckable, and Header properties and the Checked, Unchecked, and Click events.

<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">
  The quick brown fox jumps over the lazy dog.
</TextBox>
Private Sub Bold_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontWeight = FontWeights.Bold
End Sub 

Private Sub Bold_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontWeight = FontWeights.Normal
End Sub 

Private Sub Italic_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontStyle = FontStyles.Italic
End Sub 

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

Private Sub IncreaseFont_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If textBox1.FontSize < 18 Then
        textBox1.FontSize += 2
    End If 
End Sub 

Private Sub DecreaseFont_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If textBox1.FontSize > 10 Then
        textBox1.FontSize -= 2
    End If 
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft