--- title: "ContextMenu Overview" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "controls [WPF], ContextMenu" - "ContextMenu controls [WPF], about ContextMenu controls" ms.assetid: 16909c42-799a-4561-91e0-7d69dcfeea91 --- # ContextMenu Overview The class represents the element that exposes functionality by using a context-specific . Typically, a user exposes the in the [!INCLUDE[TLA#tla_ui](../../../includes/tlasharptla-ui-md.md)] by right-clicking the mouse button. This topic introduces the element and provides examples of how to use it in [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] and code. ## ContextMenu Control A is attached to a specific control. The element enables you to present users with a list of items that specify commands or options that are associated with a particular control, for example, a . Users right-click the control to make the menu appear. Typically, clicking a opens a submenu or causes an application to carry out a command. ## Creating ContextMenus The following examples show how to create a with submenus. The controls are attached to button controls. [!code-xaml[ContextMenu#1](~/samples/snippets/csharp/VS_Snippets_Wpf/ContextMenu/CSharp/Pane1.xaml#1)] [!code-csharp[ContextMenu#2](~/samples/snippets/csharp/VS_Snippets_Wpf/ContextMenu/CSharp/Pane1.xaml.cs#2)] [!code-vb[ContextMenu#2](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ContextMenu/VisualBasic/Pane1.xaml.vb#2)] ## Applying Styles to a ContextMenu By using a control , you can dramatically change the appearance and behavior of a without writing a custom control. In addition to setting visual properties, you can also apply styles to parts of a control. For example, you can change the behavior of parts of the control by using properties, or you can add parts to, or change the layout of, a . The following examples show several ways to add styles to controls. The first example defines a style called `SimpleSysResources`, which shows how to use the current system settings in your style. The example assigns as the color and as the color of the . ```xaml ``` The following example uses the element to change the appearance of a in response to events that are raised on the . When a user moves the mouse over the menu, the appearance of the items changes. ```xaml ``` ## See also - - - - - [ContextMenu](contextmenu.md) - [ContextMenu Styles and Templates](contextmenu-styles-and-templates.md) - [WPF Controls Gallery Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Getting%20Started/ControlsAndLayout)