break

WPF: Menu tag

I have been using Orcas Express Edition to start playing around with the WPF (Windows Presentation Foundation ) windows.

I was trying to build a menu which has several report options, and when the user clicks on a menu you can see the report in the datagrid. In this post I’m only going to write about building the menu.

Here’s an example of a menu in WPF:

<Menu Width=”100″ Margin=”0, 0, 0, 0″ HorizontalAlignment=”left” Background=”White”>
<MenuItem Header=”_File”>
<MenuItem Header=”_New” Click=”DisplayNew”/>
<MenuItem Header=”_Open” />
</MenuItem></Menu>

When you create a WPF Window, it creates two files, e.g: Window.xaml,Window.xaml.cs.The XML this example uses is called XAML ( which is inside my Window.xaml ), which is used in the .NET Framework 3.0 technologies, specially in WPF. The interesting thing about this WPF concept is that if you are interested for a control to have certain event you need to specify it in the XAML. As you can see when the user clicks “New” in my menu, I’m going to call a method called “DisplayNew” which is inside my Window.xaml.cs.

The Window.xaml.cs will look like this:

private void DisplayNew(object sender, System.Windows.RoutedEventArgs e)
{
// In here you can decide what to do when the menu item is clicked
}

In the Window.xaml.cs you actually need to type this method manually.  It will not be created for you by Orcas. So this is how the example should look:
WPF Menu

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

CAPTCHA Image
Reload Image