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
contextMenu w/ shortcuts hlp needed
posted

I have Cut, Copy, Delete and Paste custom commands in my ViewModel.  They all work fine via the contextMenu.  However, I have two problems trying to get shortcuts to work with them. 

1)  Ctrl-V, X, C never hit the command_executed.  For example, hitting Ctrl-V for Paste never hits the code for the Paste function.  However, if I make it Ctrl-B, it does hit the code and works fine.  Copy and Cut and suffer the same problem.  Delete DOES hit the code ever since i set AllowDelete=false in the FieldLayoutSettings. Could the man app, since it already has shortcuts for X, V, C etc be stealing what i want to do?  How to restrict it to the xamDataPresenter only, not the app?

2)  When the code is hit with, say, Ctrl-J for Cut, the e.Parameter is null, so my function cannot operate.  When i use the contextMenu, e.Parameter is the xamDataPresenter.  Paste works because it does not need the xamDataPresenter as parameter.

How can i make the shortcuts function with correct keys AND then function correctly w/ datapresenter?

Attached is pertinent ViewModel code for CutCommand (this forum always cuts it off for some reason)

void CutCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
e.CanExecute = true;
e.Handled = true;         }
void CutCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        { 
            XamDataPresenter xamDataPresenter = e.Parameter as XamDataPresenter;
            if (xamDataPresenter != null)
            {
                // do work here
            }
        }

this.CutCommand = new RoutedCommand();
            this.CutCommand.InputGestures.Add(new KeyGesture(Key.B, ModifierKeys.Control));
            this.CutCommandBinding = new CommandBinding();
            this.CutCommandBinding.Command = this.CutCommand;
            this.CutCommandBinding.Executed += new ExecutedRoutedEventHandler(CutCommandBinding_Executed);
            this.CutCommandBinding.CanExecute += new CanExecuteRoutedEventHandler(CutCommandBinding_CanExecute);


and XAML:

...

<igDP:XamDataPresenter x:Name="Presenter" DataSource="{Binding Path=MyView}"
                                  
                                
                                   BindToSampleData="False" IsNestedDataDisplayEnabled="False"
                                   IsGroupByAreaExpanded="False" AutoFit="True" 
                                   
                                   IsUndoEnabled="True" 
                                   RecordAdded="Presenter_RecordAdded" RecordUpdating="Presenter_RecordUpdating"
                                   RecordsDeleting="Presenter_RecordsDeleting"
                                   PreviewMouseLeftButtonDown="Presenter_PreviewMouseLeftButtonDown"
                                   InitializeTemplateAddRecord="Presenter_InitializeTemplateAddRecord">
                
                <igDP:XamDataPresenter.ContextMenu>
                    <ContextMenu x:Name="Menu">
                        <MenuItem Header="Cut" Command="{Binding Path=CutCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Copy" Command="{Binding Path=CopyCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Paste" Command="{Binding Path=PasteCommand}"/>
                        <Separator/>
                        <MenuItem Header="Delete" Command="{Binding Path=DeleteCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                        <MenuItem Header="Print" Command="{Binding Path=PrintCommand}"
                                  CommandParameter="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                    </ContextMenu>
                </igDP:XamDataPresenter.ContextMenu>
                <igDP:XamDataPresenter.FieldLayoutSettings>
                    <igDP:FieldLayoutSettings AutoArrangeCells="Never" AllowDelete="False"
                                              AutoGenerateFields="False" 
                                              AllowClipboardOperations="None"
                                              CopyFieldLabelsToClipboard="True"
                                              AddNewRecordLocation="OnBottomFixed" 
                                              AllowAddNew="True">
                        <igDP:FieldLayoutSettings.DefaultRowDefinition>
                            <RowDefinition Focusable="True" />
                        </igDP:FieldLayoutSettings.DefaultRowDefinition>
                    </igDP:FieldLayoutSettings>
                </igDP:XamDataPresenter.FieldLayoutSettings>
                <igDP:XamDataPresenter.FieldLayouts>
                    <igDP:FieldLayout>
                        <igDP:FieldLayout.Settings>
                            <igDP:FieldLayoutSettings LabelLocation="SeparateHeader" AllowClipboardOperations="None"
                                                      RecordSeparatorLocation="FixedRecords"
                                                      HighlightAlternateRecords="True"/>
                        </igDP:FieldLayout.Settings>
                        
                            
                                    
Parents
No Data
Reply
  • 4475
    posted

    Hello,

     

    I have been looking into your sample I did not quite understand why are you defining a custom Cut command when there is such a build in command.

    Using the build in ApplicationCommands.Cut command I easily achieved the needed operation like this:

     

    <Grid.CommandBindings>

                <CommandBinding Command="Cut" CanExecute="CutCommandBinding_CanExecute" Executed="CutCommandBinding_Executed"/>

            </Grid.CommandBindings>

    .

    .

    <igDP:XamDataPresenter.ContextMenu>

                    <ContextMenu x:Name="Menu">

                        <MenuItem Header="Cut" Command="Cut" />

                     </ContextMenu>

                </igDP:XamDataPresenter.ContextMenu>

     

    Can you please give me some additional explanation as well as some small isolated sample.

    Please do not hesitate to ask in case of future concerns regarding the discussed matter.

     

    Sincerely,

    Ekaterina

    Developer Support Engineer

    Infragistics, Inc.

    www.infragistics.com/support

     

Children