How can I disable a shortcut key in my code


I know that Diagram has defined some standard shortcut keys like Ctrl+C, Ctrl+V... What I need is that I need use Ctrl+G for my own purpose in my code, but I found that this shortcut has been used by Diagram probbaly for building a group. So can you give me suggestion on how can I disable it so that I can put some functionality to it. Also do you have a table listing all standard(pre-defined) shortcuts used by Diagram.

Do you want to disable the “Group” command – i.e. cause CommandHandler.CanGroup() to return false? If so, set Diagram.AllowGroup to false.

(The same thing goes for the “Ungroup” command: set Diagram.AllowUngroup to false.)

But it sounds like you just want to handle control-G for your own command. Are you using Silverlight or WPF?

If you are using GoSilverlight, you need to replace the Diagram.CommandHandler with one that overrides DoKeyDown to handle control-G and that calls the base method otherwise.

If you are using GoWPF, you just need to remove the command bindings for Group (and Ungroup?) from Diagram.CommandBindings and then add your own.

Yeah, I am using Silverlight 4 and I will try override DoKeyDown. Thanks for your reply!

public class CustomCommandHandler : CommandHandler { public override void DoKeyDown(System.Windows.Input.KeyEventArgs e) { bool control = (Keyboard.Modifiers & ModifierKeys.Control) != 0; if (control && e.Key == System.Windows.Input.Key.G) { // ... } else { base.DoKeyDown(e); } } }
Install with:
myDiagram.CommandHandler = new CustomCommandHandler();
or with:

<go:Diagram . . .> <go:Diagram.CommandHandler> <local:CustomCommandHandler /> </go:Diagram.CommandHandler> </go:Diagram>

I’ve done just like your sample code and I got what I want and no issue so far. Thanks.