<Window x:Class="WpfApplication2.shortKey"
xmlns="
http://schemas.microsoft.com/winfx/2...l/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
xmlns:telerik="
http://schemas.telerik.com/2008/xaml/presentation"
Title="shortKey" Height="292" Width="415">
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:shortKey.ctrlRCommand}" Executed="OnCommandExec"/>
<CommandBinding Command="{x:Static local:shortKey.f2Command}" Executed="OnCommadExecF2"/>
</Window.CommandBindings>
<Grid>
</Grid>
</Window>
Code Behind
public static RoutedCommand ctrlRCommand = new RoutedCommand();
public static RoutedCommand f2Command = new RoutedCommand();
public shortKey()
{
InitializeComponent();
ctrlRCommand.InputGestures.Add(new KeyGesture(Key.R, ModifierKeys.Control));
f2Command.InputGestures.Add(new KeyGesture(Key.F2));
}
private void OnCommandExec(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Ctrk+R Press");
}
private void OnCommadExecF2(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("F2 Press");
}