Using EventTrigges in GridViewDataColumns

2 posts, 0 answers
  1. Marcus
    Marcus avatar
    43 posts
    Member since:
    Aug 2012

    Posted 05 Feb 2016 Link to this post

    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:EventTrigger EventName="KeyDown">
             <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=DataContext.OpenNachschlagText}" />


    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


  2. Petya
    Petya avatar
    989 posts

    Posted 09 Feb 2016 Link to this post

    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.

    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
Back to Top