Edit this page

RadialMenu Commands

RadRadialMenu control supports the following commands:

  • Open Command - executes before the RadRadialMenu opens;

  • Close Command - executes before the RadRadialMenu closes;

  • NavigateToView Command - executes before the user navigates to another view (child items). This command receives a context of type NavigateContext, which exposes the following properties:

    • MenuItemTarget - gets the current RadialMenuItem that has been clicked/tapped.

    • MenuItemSource - gets the previous (if any) RadialMenuItem that has been used to navigate through.

  • NavigateBack Command - (introduced with Q2 2016) navigates back to the parent item of the current RadRadialMenuItem.

Example 1 demonstrates how to navigate to another view in the RadRadialMenu using the NavigateToView command:

Example 1: Executing the NavigateToView command

NavigateContext context = new NavigateContext(menuItem);
this.radialMenu.CommandService.ExecuteCommand(Telerik.Windows.Controls.RadialMenu.Commands.CommandId.NavigateToView, context);

When the command executes the RadialMenu will navigate to the item passed as a parameter to the constructor of the NavigateContext class.

Custom Commands

RadRadialMenu exposes a commands collection that allows you to register custom commands with each control's instance through the RadRadialMenu.Commands property.

To implement a command you need to create a class that derives from the RadialMenuCommand class and override the CanExecute and Execute methods.

RadialMenuCommand class exposes the following properties:

  • Id - this value is used to associate a command with a known event within a RadRadialMenu instance;

  • Owner - gets the RadRadialMenu instance that has executed this command.

Custom commands have higher priority than the default commands.

The next example will show how to implement custom command that will be executed when the user navigates to the children of a menu item:

  1. First, create a custom class that inherits from the RadialMenuCommand class. You need to set the Id of the command to specify when it will be executed. If you wish to execute the default behavior, then you have to call the Owner.CommandService.ExecuteDefaultCommand method in the Execute method of the command as shown in Example 2.

    Example 2: Creating a custom command

        public class CustomMenuCommand : RadialMenuCommand
        {
            public CustomMenuCommand()
            {
                this.Id = CommandId.NavigateToView;
            }
    
            public override void Execute(object parameter)
            {
                base.Execute(parameter);
                var context = parameter as NavigateContext;
                var source = context.MenuItemSource; // parent menu item
                var target = context.MenuItemTarget; // current menu item
    
                // put your custom command logic here
    
                this.Owner.CommandService.ExecuteDefaultCommand(CommandId.NavigateToView, context);
            }
    
            public override bool CanExecute(object parameter)
            {
                return true;
            }
        }
    
  2. Then you have to define an instance of the custom command class in the Commands collection of the RadRadialMenu as demonstrated in Example 3.

    Example 3: Setting the custom command

        <telerik:RadRadialMenu>
            <telerik:RadRadialMenu.Commands>
                <local:CustomMenuCommand />
            </telerik:RadRadialMenu.Commands>
            <telerik:RadRadialMenuItem Header="Item 1" >
                <telerik:RadRadialMenuItem Header="Item 1.1">
                    <telerik:RadRadialMenuItem Header="Item 1.1.1" />
                </telerik:RadRadialMenuItem>
                <telerik:RadRadialMenuItem Header="Item 1.2" >
                    <telerik:RadRadialMenuItem Header="Item 1.2.1" />
                </telerik:RadRadialMenuItem>
            </telerik:RadRadialMenuItem>
        </telerik:RadRadialMenu>
    

    See Also

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy