Articles in this section

How to map the custom commands to existing gestures (keyboard shortcuts and mouse) in WPF Diagram (SfDiagram)?

WPF Diagram (SfDiagram) provides support to map or bind command execution with desired combination of key gestures and some built-in commands. The CommandManager provides support to define custom commands. The custom commands are executed, when the specified key gesture is recognized.

To define a custom command, specify the following properties.

  1. Gesture: Class represents the combination of keys, key modifiers, and key states.
  2. Command: Property for custom command.
  3. Parameter: Property for additional information for the command execution. This is not a mandatory to set.

Refer to the following code example and sample for creating the custom command to save the diagram.

ObservableCollection<IGestureCommand> commands= diagram.CommandManager.Commands;
 
 //DataContext of the window or diagram
 CommandViewModel viewModel = (this.DataContext as CommandViewModel);
 
 //Create GestureCommand with gesture keys and commands.
 GestureCommand command = new GestureCommand();
 Gesture gesture = new Gesture()
 {
   Key = Key.S,
   KeyModifiers = ModifierKeys.Control,
   KeyState = KeyStates.Down
};
command.Gesture = gesture;
//Set command from viewmodel to diagram
command.Command =viewModel==null? viewModel.Save:null;
command.Parameter = this.diagram;
 
commands.Add(command);

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied