Class KeyboardCommand
Represents a command associated with a keyboard gesture within a diagram component.
Inherited Members
Namespace: Syncfusion.Blazor.Diagram
Assembly: Syncfusion.Blazor.dll
Syntax
public class KeyboardCommand : DiagramObject, IDiagramObject, ICloneable
Remarks
This class is utilized primarily to define keyboard shortcuts within a diagram. Each command is tied to a specific key gesture, which is used for triggering operations such as grouping or ungrouping diagram elements.
Examples
The following example illustrates how to create and use custom keyboard commands within a SfDiagramComponent.
<SfDiagramComponent @ref="@diagram" Height="600px" Nodes="@nodes">
@* Initializing the custom commands *@
<CommandManager Commands="@command">
</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, Modifiers = ModifierKeys.Control }
},
new Command()
{
Name = "CustomUngroup",
Gesture = new KeyGesture() { Key = DiagramKeys.U, Modifiers = ModifierKeys.Control }
},
};
}
Constructors
KeyboardCommand()
Declaration
public KeyboardCommand()
Properties
Gesture
Gets or sets a gesture that combines a key with modifier keys to execute a command.
Declaration
public KeyGesture Gesture { get; set; }
Property Value
Type | Description |
---|---|
KeyGesture | A KeyGesture representing the key and modifier combination that triggers the command.
The default value is a new KeyGesture instance with |
Remarks
This property is used primarily to define custom keyboard shortcuts within a diagram component, facilitating operations like grouping or ungrouping elements.
Custom commands can be implemented within a SfDiagramComponent by defining specific key gestures.
Examples
The following example demonstrates how to create and implement custom keyboard commands using the SfDiagramComponent.
<SfDiagramComponent @ref="@diagram" Height="600px" Nodes="@nodes">
@* Initializing the custom commands *@
<CommandManager Commands="@command">
</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, Modifiers = ModifierKeys.Control }
},
new Command()
{
Name = "CustomUngroup",
Gesture = new KeyGesture() { Key = DiagramKeys.U, Modifiers = ModifierKeys.Control }
},
};
}
Name
Gets or sets the name of the command.
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String | A System.String representing the name of the command. The default value is an empty string. |
Remarks
This property is essential for identifying the command within the diagram's command manager. Command names should be unique to avoid conflicts when assigning multiple commands.
Examples
<SfDiagramComponent @ref="@diagram" Height="600px" Nodes="@nodes">
@* Initializing the custom commands*@
<CommandManager Commands = "@command">
</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, Modifiers = ModifierKeys.Control }
},
new Command()
{
Name = "CustomUngroup",
Gesture = new KeyGesture() { Key = DiagramKeys.U, Modifiers = ModifierKeys.Control }
},
};
}
}
Parameter
Gets or sets all additional parameters required at runtime for KeyboardCommands.
Declaration
public string Parameter { get; set; }
Property Value
Type | Description |
---|---|
System.String | A System.String containing parameter names. The default value is an empty string. |
Remarks
This property is utilized to pass custom parameters that are necessary during the execution of keyboard commands.