<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
|