Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

Menus

Many windows applications provide access to their functionality through a hierarchy of menus. These are typically presented either as a main menu at the top of the window, or as a pop-up "context" menu. WPF provides two menu controls. Menu is for permanently visible menus (such as a main menu), and ContextMenu is for context menus.

Tip

Menus in pre-WPF Windows applications are typically treated differently from other user interface elements. In Win32, menus get a distinct handle type and special event handling provisions. In Windows Forms, most visible elements derive from a Control base class, but menus do not. This means that menus tend to be somewhat inflexible—some user interface toolkits choose not to use the built-in menu handling in Windows simply to avoid the shortcomings. In WPF, menus are just normal controls, so they do not have any special features or restrictions.

Both kinds of menus are built in the same way—their contents consist of a hierarchy of MenuItem elements. Example 5-22 shows a typical example.

Example 5-22. A main menu

<Menu> <MenuItem Header="_File"> <MenuItem Header="_New" /> <MenuItem Header="_Open..." /> <MenuItem Header="_Save" /> <MenuItem Header="Sa_ve As..." /> <Separator /> <MenuItem Header="Page Se_tup..." /> <MenuItem Header="_Print..." /> <Separator /> <MenuItem Header="E_xit" /> </MenuItem> <MenuItem Header="_Edit"> <MenuItem Header="_Undo" /> <MenuItem Header="_Redo" /> <Separator /> <MenuItem Header="Cu_t" /> <MenuItem Header="_Copy" /> <MenuItem ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page