title | page_title | description | slug | tags | published | position |
---|---|---|---|---|---|---|
Getting Started |
Getting Started |
Check our "Getting Started" documentation article for the RadContextMenu {{ site.framework_name }} control. |
contextmenu-getting-started |
getting,started |
true |
3 |
This tutorial will walk you through the creation of a RadContextMenu and will show you how to:
Before reading this tutorial you should get familiar with the [Visual Structure]({%slug radcontextmenu-visual-structure%}) of the standard RadContextMenu control.
To use the RadContextMenu in your projects you have to add references to the following assemblies:
- Telerik.Licensing.Runtime
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Navigation
You can find the required assemblies for each control from the suite in the {% if site.site_name == 'Silverlight' %}[Controls Dependencies]({%slug installation-installing-controls-dependencies%}){% else %}[Controls Dependencies]({%slug installation-installing-controls-dependencies-wpf%}){% endif %} help article.
tip With the 2025 Q1 release, the Telerik UI for WPF has a new licensing mechanism. You can learn more about it [here]({%slug installing-license-key%}).
To use RadContextMenu when working with NuGet packages, install the Telerik.Windows.Controls.Input.for.Wpf.Xaml
package. The [package name may vary]({%slug nuget-available-packages%}) slightly based on the Telerik dlls set - [Xaml or NoXaml]({%slug xaml-vs-noxaml%})
Read more about NuGet installation in the [Installing UI for WPF from NuGet Package]({%slug nuget-installation%}) article.
In order to add a RadContextMenu control to your UserControl you have to declare the following namespace:
{{region xaml-contextmenu-getting-started_0}} xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" {{endregion}}
This tutorial will show you how to attach a RadContextMenu to a TextBox control. Here is the TextBox control definition.
{{region xaml-contextmenu-getting-started_1}} {{endregion}}
The next step is to set the ContextMenu attached property of the RadContextMenu class to the TextBox control.
{% if site.site_name == 'WPF' %}
ContextMenu="{x:Null}" is needed to override the default context menu of the textbox.
{{region xaml-contextmenu-getting-started_2}} telerik:RadContextMenu.ContextMenu <telerik:RadContextMenu /> </telerik:RadContextMenu.ContextMenu> {{endregion}} {% endif %}
{% if site.site_name == 'Silverlight' %}
{{region xaml-contextmenu-getting-started_3}} telerik:RadContextMenu.ContextMenu telerik:RadContextMenu <telerik:RadMenuItem Header="Copy" /> <telerik:RadMenuItem Header="Paste" /> <telerik:RadMenuItem Header="Cut" /> <telerik:RadMenuItem IsSeparator="True" /> <telerik:RadMenuItem Header="Select All" /> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> {{endregion}} {% endif %}
If you run the application and right-click on the TextBox you will see an empty context menu.
The class that represents the menu item is Telerik.Windows.Controls.RadMenuItem. To learn more about it, please take a look at the [RadMenu help content]({%slug radmenu-overview%}).
The RadContextMenu accepts RadMenuItems as child items. Here is a sample declaration of several child menu items.
{% if site.site_name == 'Silverlight' %}
{{region xaml-contextmenu-getting-started_5}} telerik:RadContextMenu.ContextMenu telerik:RadContextMenu <telerik:RadMenuItem Header="Copy" /> <telerik:RadMenuItem Header="Paste" /> <telerik:RadMenuItem Header="Cut" /> <telerik:RadMenuItem IsSeparator="True" /> <telerik:RadMenuItem Header="Select All" /> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> {{endregion}} {% endif %}
{% if site.site_name == 'WPF' %}
{{region xaml-contextmenu-getting-started_3}} telerik:RadContextMenu.ContextMenu telerik:RadContextMenu <telerik:RadMenuItem Header="Copy" /> <telerik:RadMenuItem Header="Paste" /> <telerik:RadMenuItem Header="Cut" /> <telerik:RadMenuItem IsSeparator="True" /> <telerik:RadMenuItem Header="Select All" /> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> {{endregion}} {% endif %}
Here is a snapshot of the result.
The scenario described in the previous sections covers the usage of static items. To learn more about these type of scenarios read [here]({%slug radcontextmenu-populating-with-data-using-static-items%}).
However, in most of the cases you have to bind your RadContextMenu to a collection of business objects. Check out the following topics which describe in details how to work with dynamic data.
-
[Data Binding Support Overview]({%slug radcontextmenu-populating-with-data-data-binding-support-overview%}) - describes the various data sources for the RadContextMenu and shows you many tips and tricks. Read this topics in order to achieve basic knowledge about how the binding mechanism works at the RadContextMenu.
-
[Binding to Dynamic Data]({%slug radcontextmenu-populating-with-data-using-static-items%}) - shows you how to bind the RadContextMenu to a collection of business objects.
-
[Template and Styles Selectors]({%slug radcontextmenu-populating-with-data-template-and-style-selectors%}) - describes the possibilities to adjust the appearance of the RadContextMenu's items depending on the data they hold.
Read the [Styles and Templates]({%slug radcontextmenu-styles-and-templates-overview%}) section which is entirely dedicated to styling and templating the RadContextMenu control.
In order to learn how to use the RadContextMenu and what capabilities it holds, read the various topics that describe its features.
-
[Working with the RadContextMenu]({%slug radcontextmenu-features-working-with-radcontext-menu%})
-
[Opening on a Specific Event]({%slug radcontextmenu-features-opening-on-specific-event%})
-
[Key Modifiers]({%slug radcontextmenu-key-modifiers%})
-
[Placement]({%slug radcontextmenu-features-placement%})
-
[Opening and Closing Delays]({%slug radcontextmenu-features-opening-and-closing-delays%})
-
[Data Binding]({%slug radcontextmenu-features-data-binding%}) {% if site.site_name == 'Silverlight' %}
-
[Boundaries Detection]({%slug radcontextmenu-features-boundaries-detection%}) {% endif %}
The controls from our suite support different themes. You can see how to apply a theme different than the default one in the [Setting a Theme]({%slug styling-apperance-implicit-styles-overview%}) help article.
important Changing the theme using implicit styles will affect all controls that have styles defined in the merged resource dictionaries. This is applicable only for the controls in the scope in which the resources are merged.
To change the theme, you can follow the steps below:
-
Choose between the themes and add reference to the corresponding theme assembly (ex: Telerik.Windows.Themes.Windows8.dll). You can see the different themes applied in the Theming examples from our {% if site.site_name == 'WPF' %}WPF Controls Examples{% else %}Silverlight Controls Examples{% endif %} application.
-
Merge the ResourceDictionaries with the namespace required for the controls that you are using from the theme assembly. For the RadContextMenu, you will need to merge the following resources:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Navigation
Example 5 demonstrates how to merge the ResourceDictionaries so that they are applied globally for the entire application.
{{region xaml-radcontextmenu-getting-started_7}} <Application.Resources> <ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries> </Application.Resources> {{endregion}}
Alternatively, you can use the theme of the control via the {% if site.site_name == 'WPF' %}StyleManager{% else %}StyleManager{% endif %}.
Figure 3 shows a RadContextMenu with the Windows8 theme applied.
{% if site.site_name == 'WPF' %}
- Telerik UI for WPF ContextMenu Component
- [Getting Started with Telerik UI for WPF Components]({%slug getting-started-first-steps%})
- [Telerik UI for WPF Installation]({%slug installation-installing-which-file-do-i-need%})
- [Telerik UI for WPF and WinForms Integration]({%slug winforms-integration%})
- [Telerik UI for WPF Visual Studio Templates]({%slug visual-studio-templates%})
- [Setting a Theme with Telerik UI for WPF]({%slug styling-apperance-implicit-styles-overview%})
- Telerik UI for WPF Virtual Classroom (Training Courses for Registered Users)
- Telerik UI for WPF License Agreement {% endif %}
-
[Visual Structure]({%slug radcontextmenu-visual-structure%})
-
[Events - Overview]({%slug radcontextmenu-events-overview%})
-
[Styles and Templates - Overview]({%slug radcontextmenu-styles-and-templates-overview%})
-
[Use RadContextMenu with a RadGridView]({%slug radcontextmenu-how-to-use-radcontextmenu-with-radgridview%})
-
[Select the clicked Item of a RadTreeView]({%slug radcontextmenu-how-to-select-the-clicked-item-of-radtreeview%})
-
[Create Menu Button with RadContextMenu and ToggleButton]({%slug radcontextmenu-how-to-create-menu-button-with-radcontextmenu-and-togglebutton%})
-
[Use Commands with the RadContextMenu]({%slug radcontextmenu-how-to-use-commands-with-the-radcontextmenu%})
-
[Handle Item Clicks]({%slug radcontextmenu-how-to-handle-item-clicks%})