Telerik UI for Silverlight

Note

In order to use RadContextMenu you have to set your application to work in windowless mode. This is required to avoid the Silverlight information message when you right click an object inside your Silverlight application. To learn more about setting your application in windowless mode read here.

This tutorial will walk you through the creation of a RadContextMenu and will show you how to:

Note

Before reading this tutorial you should get familiar with the Visual Structure of the standard RadContextMenu control.

For the purpose of this tutorial, you will need to create an empty Silverlight Application project.

Note

In order to use RadContextMenu control in your projects you have to add references to the following assemblies:

  1. Telerik.Windows.Controls.Navigation.dll
  2. Telerik.Windows.Controls.dll

Add RadContextMenu

In order to add a RadContextMenu control to your UserControl you have to declare the following namespace:

CopyXAML
<UserControl ...
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Grid x:Name="LayoutRoot">

    </Grid>
</UserControl>

This tutorial will show you how to attach a RadContextMenu to a TextBox control. Here is the TextBox control definition.

CopyXAML
<Grid x:Name="LayoutRoot"
      Background="White">
    <TextBox x:Name="InputBox"
             Width="200"
             VerticalAlignment="Top">
    </TextBox>
</Grid>

The next step is to set the ContextMenu attached property of the RadContextMenu class to the TextBox control.

CopyXAML
<Grid x:Name="LayoutRoot"
      Background="White">
    <TextBox Width="200"
             VerticalAlignment="Top">
        <telerik:RadContextMenu.ContextMenu>
            <telerik:RadContextMenu />
        </telerik:RadContextMenu.ContextMenu>
    </TextBox>
</Grid>

If you run the application and right-click on the TextBox you will see an empty context menu.

Add Menu Items

Note

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.

Note

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.

The RadContextMenu accepts RadMenuItems as child items. Here is a sample declaration of several child menu items.

CopyXAML
<TextBox Width="200"
         VerticalAlignment="Top">
    <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>
</TextBox>

Here is a snapshot of the result.

Populating the RadContextMenu with Data

The scenario described in the previous sections covers the usage of static items. To learn more about these type of scenarios read here.

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 - 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 - shows you how to bind the RadContextMenu to a collection of business objects.
  • Template and Styles Selectors - describes the possibilities to adjust the appearance of the RadContextMenu's items depending on the data they hold.

Styles and Templates

Read the Styles and Templates section which is entirely dedicated to styling and templating the RadContextMenu control.

Work with the RadContextMenu

In order to learn how to use the RadContextMenu and what capabilities it holds, read the various topics that describe its features.

See Also