New to Telerik UI for WPF? Start 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 Version | 2023.2.606 |
| Product | RadRadialMenu 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
- 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)); }
}
}- 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)
{
}
}- 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.GetRadialContextMenumethod. Depending on the value of the bool property from the view model, execute theRadRadialMenuCommands.ShowandRadRadialMenuCommands.Hidecommands.
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);
}
}
}
}- 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>