Saturday, September 19, 2009

WPF - Using Input Gestures to add access key functionality for Hyperlinks

Input gestures to a command can be added by using KeyBinding and/or MouseBinding objects to the relevant element's InputBindings collection. I have tried to add access key functionality on the hyperlink control by following this approach.

public RoutedCommand __HyperLinkAccessKeyCommand = new RoutedCommand();

CommandBinding __CommandBinding = new CommandBinding(__HyperLinkAccessKeyCommand, (x, y) => ExecuteCommand());

this.CommandBindings.Add(__CommandBinding);

this.InputBindings.Add(new KeyBinding(__HyperLinkAccessKeyCommand, new KeyGesture(Key.O, ModifierKeys.Alt)));

No comments: