menu

Blazor

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class CommandManager - Blazor API Reference | Syncfusion

    Show / Hide Table of Contents

    Class CommandManager

    Defines the collection of commands and the corresponding key gestures. It is responsible for managing routed commands.

    Inheritance
    System.Object
    CommandManager
    Namespace: Syncfusion.Blazor.Diagram
    Assembly: Syncfusion.Blazor.dll
    Syntax
    public class CommandManager : ComponentBase
    Remarks

    CommandManager provides the support to define custom commands. The custom commands are executed when the specified key gesture is recognized.

    Examples
    <summary>
    Notifies when to execute the custom keyboard commands .
    </summary>
    <remarks>
    The following code illustrates how to create a custom command.
    </remarks>
    <example>
    <code lang="Razor">
    <![CDATA[
    <SfDiagramComponent @ref="@diagram" Height="600px" Nodes="@nodes">
    @* Initializing the custom commands*@
        <CommandManager Commands = "@command" Execute="@CommandExecute" CanExecute="@CanExe">
        </CommandManager>
    </SfDiagramComponent>
    @code
    {
        // Reference to the diagram
        SfDiagramComponent diagram;
        DiagramObjectCollection<KeyboardCommand> command = new DiagramObjectCollection<KeyboardCommand>()
        {
            new Command()
            {
                Name = "CustomGroup",
                Gesture = new KeyGesture() { Key = DiagramKeys.G, KeyModifiers = KeyModifiers.Control }
            },
            new Command()
            {
                Name = "CustomUngroup",
                Gesture = new KeyGesture() { Key = DiagramKeys.U, KeyModifiers = KeyModifiers.Control }
            },
        };
        // Define the diagram's nodes collection
        DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();
        public void CanExe(CommandKeyArgs args)
        {
            args.CanExecute = true;
        }
        public void CommandExecute(CommandKeyArgs args)
        {
            if (args.Gesture.KeyModifiers == KeyModifiers.Control && args.Gesture.Key == DiagramKeys.G)
            {
                //Custom command to group the selected nodes
                diagram.Group();
            }
            if (args.Gesture.KeyModifiers == KeyModifiers.Control && args.Gesture.Key == DiagramKeys.U)
            {
                Selector selector = diagram.SelectedItems;
                //Custom command to ungroup the selected items
                if (selector.Nodes.Count > 0 && selector.Nodes[0] is Group)
                {
                    if ((selector.Nodes[0] as Group).Children.Length > 0)
                    {
                        diagram.Ungroup();
                    }
                }
            }
        }
    }

    Constructors

    CommandManager()

    Declaration
    public CommandManager()

    Properties

    CanExecute

    Determines whether this command can execute in its current state.

    Declaration
    public EventCallback<CommandKeyArgs> CanExecute { get; set; }
    Property Value
    Type
    Microsoft.AspNetCore.Components.EventCallback<CommandKeyArgs>
    Examples
    <summary>
    Notifies when to execute the custom keyboard commands .
    </summary>
    <remarks>
    The following code illustrates how to create a custom command.
    </remarks>
    <example>
    <code lang="Razor">
    <![CDATA[
    <SfDiagramComponent >
    @* Initializing the custom commands*@
        <CommandManager CanExecute="@CanExe">
        </CommandManager>
    </SfDiagramComponent>
    @code
    {
        public void CanExe(CommandKeyArgs args)
        {
            args.CanExecute = true;
        }
    }

    ChildContent

    Gets or sets the child content of the Command Manager.

    Declaration
    public RenderFragment ChildContent { get; set; }
    Property Value
    Type
    Microsoft.AspNetCore.Components.RenderFragment

    Commands

    Represents storing multiple command names with the corresponding command object.

    Declaration
    public DiagramObjectCollection<KeyboardCommand> Commands { get; set; }
    Property Value
    Type
    DiagramObjectCollection<KeyboardCommand>
    Examples
    <summary>
    Notifies when to execute the custom keyboard commands .
    </summary>
    <remarks>
    The following code illustrates how to create a custom command.
    </remarks>
    <example>
    <code lang="Razor">
    <![CDATA[
    <SfDiagramComponent >
        <CommandManager Commands = "@command" >
        </CommandManager>
    </SfDiagramComponent>
    @code
    {
        DiagramObjectCollection<KeyboardCommand> command = new DiagramObjectCollection<KeyboardCommand>()
        {
            new Command()
            {
                Name = "CustomGroup",
                Gesture = new KeyGesture() { Key = DiagramKeys.G, Modifiers = ModifierKeys.Control }
            },
            new Command()
            {
                Name = "CustomUngroup",
                Gesture = new KeyGesture() { Key = DiagramKeys.U, Modifiers = ModifierKeys.Control }
            },
        };
    }

    CommandsChanged

    Specifies the callback to trigger when the commands changes.

    Declaration
    public EventCallback<DiagramObjectCollection<KeyboardCommand>> CommandsChanged { get; set; }
    Property Value
    Type
    Microsoft.AspNetCore.Components.EventCallback<DiagramObjectCollection<KeyboardCommand>>

    Execute

    Executes the command on the current command target.

    Declaration
    public EventCallback<CommandKeyArgs> Execute { get; set; }
    Property Value
    Type
    Microsoft.AspNetCore.Components.EventCallback<CommandKeyArgs>
    Examples
    <summary>
    Notifies when to execute the custom keyboard commands .
    </summary>
    <remarks>
    The following code illustrates how to create a custom command.
    </remarks>
    <example>
    <code lang="Razor">
    <![CDATA[
    <SfDiagramComponent >
    @* Initializing the custom commands*@
        <CommandManager  Execute="@CommandExecute" >
        </CommandManager>
    </SfDiagramComponent>
    @code
    {
        public void CommandExecute(CommandKeyArgs args)
        {
            if (args.Gesture.Modifiers == ModifierKeys.Control && args.Gesture.Key == DiagramKeys.G)
            {
                //Custom command to group the selected nodes
                diagram.Group();
            }
            if (args.Gesture.Modifiers == ModifierKeys.Control && args.Gesture.Key == DiagramKeys.U)
            {
                Selector selector = diagram.SelectedItems;
                //Custom command to ungroup the selected items
                if (selector.Nodes.Count > 0 && selector.Nodes[0] is Group)
                {
                    if ((selector.Nodes[0] as Group).Children.Length > 0)
                    {
                        diagram.Ungroup();
                    }
                }
            }
        }
    }

    Methods

    BuildRenderTree(RenderTreeBuilder)

    Declaration
    protected override void BuildRenderTree(RenderTreeBuilder __builder)
    Parameters
    Type Name Description
    Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder

    Dispose()

    This method releasing all unmanaged resources.

    Declaration
    public void Dispose()

    OnInitializedAsync()

    Method invoked when the component is ready to start.

    Declaration
    protected override Task OnInitializedAsync()
    Returns
    Type Description
    System.Threading.Tasks.Task

    A System.Threading.Tasks.Task representing any asynchronous operation.

    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved