I create WPF DataGrid with ContextMenu in one of column header as follow:
<DataGrid x:Name="grid" ItemsSource="{Binding Path=Orders}">
<DataGrid.InputBindings>
<KeyBinding Command="{Binding Path=ShowStatusHeaderContextMenuCommand}"
CommandParameter="{Binding ElementName=FristNameContextMenu}"
Gesture="Ctrl+S" />
</DataGrid.InputBindings>
<DataGrid.Columns>
<DataGridTemplateColumn Width="30" Header="Status">
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock x:Name="StatusHeaderTextBlock" Text="Status">
<TextBlock.ContextMenu>
<ContextMenu x:Name="FristNameContextMenu">
<MenuItem Command="{Binding SetCompleteFlagsCommand}" Header="Complete"/>
<MenuItem Command="{Binding ClearDeleteFlagsCommand}" Header="Deleted" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="100"
Header="Order Number"
Binding = "{Binding Path=OrderNumber}"/>
<DataGrid.Columns>
</DataGrid>
If I right click on Status column header, it brings up the ContextMenu. But I want to add a shortcut key “Control + S” to bring up the ContextMenu as well. Anyone know how to add it?
Thanks
Jing
Create a command that opens the context menu and add a
KeyBindingwith that command and your gesture to theInputBindingsof the control in whose scope the shortcut should apply.(Also:
Ctrl+Sis “Save” by convention, i am not sure if you really want to use that for a context menu)