This is a migrated thread and some comments may be shown as answers.

Using EventTrigges in GridViewDataColumns

1 Answer 221 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 05 Feb 2016, 11:04 AM

I have to react to a key-down-event in a datacell of a GridView. So in XAML I have defined the following:


<telerik:GridViewDataColumn Header="Bezeichnung" DataMemberBinding="{Binding Bezeichnung}">
   <i:Interaction.Triggers>
      <i:EventTrigger EventName="KeyDown">
         <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=DataContext.OpenNachschlagText}" />
      </i:EventTrigger>
   </i:Interaction.Triggers>
</telerik:GridViewDataColumn>

 

With this snippet of code there are no errors in the output-console (no "DataContext.OpenNachschlagText not found" or so). But my ICommand (RelayCommand in my case) is not called when I press a key on the keyboard.

What is wrong or better: how can I react on a key, for example the F5 key?

Thanks in advance

Marcus

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 09 Feb 2016, 05:19 PM
Hi Marcus, 

Please have a look at the Keyboard Command Provider help topic and related SDK demo that demonstrate how you can go about reacting to key down. Also, bear in mind that if you only want to execute the command when in edit or view mode, you may need to check this in the ProvideCommandsForKey method, for example:
if (key == Key.F5 && this.parentGrid.CurrentCell.IsInEditMode)
{
 
}

Alternatively, you could redefine the CellTempalte and CellEditTemplate for the column and subscibe to KeyDown event in them.

I hope this is useful.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or