MenuItem.Click Event
Occurs when a MenuItem is clicked.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
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 void Bold_Checked(object sender, RoutedEventArgs e) { textBox1.FontWeight = FontWeights.Bold; } private void Bold_Unchecked(object sender, RoutedEventArgs e) { textBox1.FontWeight = FontWeights.Normal; } private void Italic_Checked(object sender, RoutedEventArgs e) { textBox1.FontStyle = FontStyles.Italic; } private void Italic_Unchecked(object sender, RoutedEventArgs e) { textBox1.FontStyle = FontStyles.Normal; } private void IncreaseFont_Click(object sender, RoutedEventArgs e) { if (textBox1.FontSize < 18) { textBox1.FontSize += 2; } } private void DecreaseFont_Click(object sender, RoutedEventArgs e) { if (textBox1.FontSize > 10) { textBox1.FontSize -= 2; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.