New to Telerik UI for WPFStart a free 30-day trial

Show/Hide RadRadialMenu When Used As a Context Menu In an MVVM Scenario

Updated on Sep 15, 2025

Environment

Product Version2023.2.606
ProductRadRadialMenu for WPF

Description

Show or hide the RadRadialMenu control when it is used as a context menu for an element in an MVVM scenario.

Solution

  1. Create a property of type bool inside your view model.

Creating a view model with a bool property

C#
	public class MainViewModel : ViewModelBase
	{
	    private bool shouldOpenRadialMenu;

	    public bool ShouldOpenRadialMenu
	    {
	        get { return shouldOpenRadialMenu; }
	        set { shouldOpenRadialMenu = value; this.OnPropertyChanged(nameof(this.ShouldOpenRadialMenu)); }
	    }
	}
  1. Create an attached property that will be bound to the bool property from the view model.

Creating an attached property

C#
	public class RadialMenuExtensions
	{
	    public static int GetShouldOpenRadialMenu(DependencyObject obj)
	    {
	        return (int)obj.GetValue(ShouldOpenRadialMenuProperty);
	    }

	    public static void SetShouldOpenRadialMenu(DependencyObject obj, int value)
	    {
	        obj.SetValue(ShouldOpenRadialMenuProperty, value);
	    }

	    public static readonly DependencyProperty ShouldOpenRadialMenuProperty =
	        DependencyProperty.RegisterAttached("ShouldOpenRadialMenu", typeof(bool), typeof(RadialMenuExtensions), new PropertyMetadata(false, OnShouldOpenRadialMenuChanged));

	    private static void OnShouldOpenRadialMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	    {
	    }
	}
  1. Retrieve the RadRadialMenu instance that is set on the element as a context menu in the property callback method. To do so, use the RadRadialMenu.GetRadialContextMenu method. Depending on the value of the bool property from the view model, execute the RadRadialMenuCommands.Show and RadRadialMenuCommands.Hide commands.

Showing/Hiding the RadRadialMenu in the property callback method

C#
	private static void OnShouldOpenRadialMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
	{
	    FrameworkElement frameworkElement = d as FrameworkElement;

	    if (frameworkElement != null)
	    {
	        RadRadialMenu radRadialMenu = RadRadialMenu.GetRadialContextMenu(frameworkElement);

	        if (radRadialMenu != null )
	        {
	            bool shouldOpen = (bool)e.NewValue;

	            if (shouldOpen)
	            {
	                RadialMenuCommands.Show.Execute(null, frameworkElement);
	            }
	            else
	            {
	                RadialMenuCommands.Hide.Execute(null, frameworkElement);
	            }
	        }
	    }
	}
  1. Set the attached property on the element that has the RadRadialMenu set as its context menu and bind it to the bool property from the view model.

The following example shows the RadRadialMenu control as a context menu for a TextBox element instance:

Binding the attached property

XAML
	<Grid>
	    <Grid.DataContext>
	        <local:MainViewModel/>
	    </Grid.DataContext>
	    <TextBox local:RadialMenuExtensions.ShouldOpenRadialMenu="{Binding ShouldOpenRadialMenu, Mode=TwoWay}">
	        <telerik:RadRadialMenu.RadialContextMenu>
	            <telerik:RadRadialMenu>
	                <telerik:RadRadialMenuItem Header="Item 1" />
	                <telerik:RadRadialMenuItem Header="Item 2" />
	                <telerik:RadRadialMenuItem Header="Item 3" />
	            </telerik:RadRadialMenu>
	        </telerik:RadRadialMenu.RadialContextMenu>
	    </TextBox>
	</Grid>
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support