Tuesday, July 28, 2009

WPF Menu

Tweaking the raw Xaml is not needed in the new editions of Visual Studio.

This blog assumes that you are familiar with Xml. If not view my blog Working with Xml.

To Start with I am creating a Menu with a MenuItem called File and below that two MenuItems File, Exit and a Separator in between. It is very much possible to construct a menu with the Menu control and Properties window.

<Menu>


<MenuItem Name="mnuFile" Header="_File">


<MenuItem Name="mnuNew" Header="_New"/>


<Separator/>


<MenuItem Name="mnuExit" Header="_Exit"/>


</MenuItem>


</Menu>

Adding Event Handler to Menu








Pressing the tab key automatically created an event handler.

private void mnuExit_Click(object sender, RoutedEventArgs e)
{
Close();
}

No comments:

Post a Comment