Blazor

Upgrade Guide User Guide Demos Support Forums Download
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class CommandKeyArgs - Blazor API Reference | Syncfusion

    Show / Hide Table of Contents

    Class CommandKeyArgs

    Notifies when to execute the custom keyboard commands .

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

    The following code illustrates how to create a custom command.

    Examples
    <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 KeyboardCommand()
            {
                Name = "CustomGroup",
                Gesture = new KeyGesture() { Key = Keys.G, Modifiers = ModifierKeys.Control }
            },
            new KeyboardCommand()
            {
                Name = "CustomUnGroup",
                Gesture = new KeyGesture() { Key = Keys.U, Modifiers = ModifierKeys.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.Modifiers == ModifierKeys.Control && args.Gesture.Key == Keys.G)
            {
                //Custom command to group the selected nodes
                diagram.Group();
            }
            if (args.Gesture.Modifiers == ModifierKeys.Control && args.Gesture.Key == Keys.U)
            {
                DiagramSelectionSettings selector = diagram.SelectionSettings;
                //Custom command to ungroup the selected items
                if (selector.Nodes.Count > 0 && selector.Nodes[0] is NodeGroup)
                {
                    if ((selector.Nodes[0] as NodeGroup).Children.Length > 0)
                    {
                        diagram.UnGroup();
                    }
                }
            }
        }
    }

    Constructors

    CommandKeyArgs()

    Declaration
    public CommandKeyArgs()

    Properties

    CanExecute

    Defines the method that determines whether the command can be executed in its current state.

    Declaration
    public bool CanExecute { get; set; }
    Property Value
    Type Description
    System.Boolean

    Gesture

    Specifies a combination of keys and key modifiers, on recognition of which the command should be executed.

    Declaration
    public KeyGesture Gesture { get; }
    Property Value
    Type Description
    KeyGesture

    Name

    Specifies the name of the command.

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    System.String
    Back to top Generated by DocFX
    Copyright © 2001 - 2022 Syncfusion Inc. All Rights Reserved