开发者

In WPF how to add menu item event?

In my WPF application, I add a menu then add several menu items under it. For example, one of my menu item is "Main Item", then I add subItem1, subItem2 and subItem3 under "Main Item". I want to click subItem1 and do something(e.g. MessageBox.show a m开发者_如何学运维essage). Why I cannot find the event for this subItem1? How can I add the click event for subItem1? I find the property for subItem1 under the collection property for "Main Item", but can only see property, cannot see event list. How can I add click event for subItem1? Thank you!


In your xaml:

<Menu IsMainMenu="True">
<MenuItem Header="MainMenu">
<MenuItem Header="subItem1" 
 x:Name="subItem1" Click="subItem1_Click">
</MenuItem>
</MenuItem>
</Menu>

In your code-behind:

private void subItem1_Click(object sender, RoutedEventArgs e)
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜