Telerik UI for Windows Phone by Progress

Note

The following XAML namespace must be declared in order to use RadContextMenu:

CopyXAML
xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"

Defining RadContextMenu inline

In order to associate RadContextMenu with a visual element the RadContextMenu.ContextMenu attached property must be set on that element. For example:

CopyXAML
<Rectangle Fill="White"
           Width="200"
           Height="200"
           x:Name="rectangle">
    <telerikPrimitives:RadContextMenu.ContextMenu>
        <telerikPrimitives:RadContextMenu IsFadeEnabled="False"
                                          IsZoomEnabled="False">
            <telerikPrimitives:RadContextMenuItem Content="change color" 
                                                  Tapped="OnChangeColorTapped"/>
            <telerikPrimitives:RadContextMenuItem Content="clear color"
                                                  Tapped="OnClearColorTapped"/>
        </telerikPrimitives:RadContextMenu>
    </telerikPrimitives:RadContextMenu.ContextMenu>
</Rectangle>

Using the menu

Now that we have defined a context menu for our handy rectangle, we have to make the menu items execute some action when they are tapped. We do this by subscribing to each item's Tapped event as can be seen in the xaml above and implementing the event handlers. For example:

CopyC#
private void OnChangeColorTapped(object sender, ContextMenuItemSelectedEventArgs e)
{
    this.rectangle.Fill = new SolidColorBrush(Colors.Green);
}

private void OnClearColorTapped(object sender, ContextMenuItemSelectedEventArgs e)
{
    this.rectangle.Fill = (Brush)Application.Current.Resources["PhoneForegroundBrush"];
}

And that's it! This is the simplest case in which RadContextMenu can be used.

Note

It is important to know that RadContextMenu opens asynchronously. Setting the IsOpen property to true will not block the UIThread.