Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
875
How to make keyboard shortcuts work in grid's context menu?
posted

I have my ContextMenu set up how i want it.  Where do i put the InputBindings and Keybindings xaml to function inside the XamDataPresenter control? 

 

Something like (for Cut:

<igDP:XamDataPresenter.InputBindings>
       
<KeyBinding Key="X"
                   
Modifiers="Ctrl"
                   
Command="{Binding Path=CutCommand}"/> //what do put here-this binding doesn't work
   
</
igDP:XamDataPresenter .InputBindings>

 

<igDP:XamDataPresenter.ContextMenu>
                    <ContextMenu x:Name="Menu">
                        <MenuItem Header="Cut" InputGestureText="Ctrl+X" Command="{Binding Path=CutCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Copy" InputGestureText="Ctrl+C" Command="{Binding Path=CopyCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Paste" InputGestureText="Ctrl+V" Command="{Binding Path=PasteCommand}"/>
                        <Separator/>
                        <MenuItem Header="Delete" InputGestureText="Delete" Command="{Binding Path=DeleteCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Print" InputGestureText="Ctrl+P" Command="{Binding Path=PrintCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                    </ContextMenu>
                </igDP:XamDataPresenter.ContextMenu>

Parents
  • 138253
    Offline posted

    Hello,

    Thank you for your post. I have been looking into it and I suggest you create Instances of the Commands in your Window’s Resources and bind the KeyBinding’s Command to these instance through the StaticResources. Please let me know if this helps you or you need further clarifications on this matter.

    Looking forward for your reply.

Reply Children