MenuItem.Click 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在单击 MenuItem 时发生。
public:
event System::Windows::RoutedEventHandler ^ Click;
public event System.Windows.RoutedEventHandler Click;
member this.Click : System.Windows.RoutedEventHandler
Public Custom Event Click As RoutedEventHandler
事件类型
示例
以下示例创建一个 Menu 来操作 TextBox 中的文本。 Menu 包含 MenuItem 对象,这些对象使用 Command、IsCheckable 和 Header 属性以及 Checked、Unchecked 和 Click 事件。
<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;
}
}
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
注解
Click如果 具有子菜单,MenuItem则不会发生该事件。
路由事件信息
标识符字段 | ClickEvent |
路由策略 | 鼓 泡 |
委托 | RoutedEventHandler |