title: Set InputBinding(KeyboardBinding) in ListViewItem
body: <p>I wish to set the Inputbinding of a listViewitem ... It should be a Keyborad binding and not a mouse binding...</p>
  <p>I want to Execute a function in my view model when the User selectes an item and presses <code>Enter</code> Key</p>
  <h1>Style for ListViewItem</h1>
  <pre><code>    &lt;Style x:Key=&quot;{ComponentResourceKey TypeInTargetAssembly={x:Type CustomView:PlainView},
                                      ResourceId=ImageViewItem}&quot;           
         TargetType=&quot;{x:Type ListViewItem}&quot; BasedOn=&quot;{StaticResource {x:Type ListViewItem}}&quot;&gt;
  
      &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Center&quot; /&gt;
      &lt;Setter Property=&quot;FocusVisualStyle&quot; Value=&quot;{StaticResource ListViewItemFocusVisual}&quot; /&gt;
      &lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;Transparent&quot; /&gt;
      &lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;1&quot; /&gt;
      &lt;Setter Property=&quot;Margin&quot; Value=&quot;0,0,0,1&quot; /&gt;
      &lt;Setter Property=&quot;Padding&quot; Value=&quot;5,2,5,2&quot; /&gt;
      &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Center&quot; /&gt;
      &lt;Setter Property=&quot;Focusable&quot; Value=&quot;False&quot;&gt;&lt;/Setter&gt;
      &lt;Setter Property=&quot;Template&quot;&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType=&quot;{x:Type ListViewItem}&quot;&gt;
                  &lt;Border x:Name=&quot;border&quot;
                          BorderBrush=&quot;{TemplateBinding BorderBrush}&quot;
                          BorderThickness=&quot;{TemplateBinding BorderThickness}&quot;
                          CornerRadius=&quot;2&quot;
                          SnapsToDevicePixels=&quot;true&quot;&gt;
                      &lt;Grid Margin=&quot;2,0,2,0&quot;&gt;
                          &lt;Rectangle x:Name=&quot;BackgroundGradientOver&quot;
                                     Fill=&quot;{DynamicResource MouseOverBrush}&quot;
                                     Opacity=&quot;0&quot;
                                     RadiusX=&quot;1&quot;
                                     RadiusY=&quot;1&quot;
                                     Stroke=&quot;{DynamicResource MouseOverBorderBrush}&quot; /&gt;
                          &lt;Rectangle x:Name=&quot;BackgroundGradientSelectedDisabled&quot;
                                     Fill=&quot;{DynamicResource ListItemSelectedBrush}&quot;
                                     Opacity=&quot;0&quot;
                                     RadiusX=&quot;1&quot;
                                     RadiusY=&quot;1&quot;
                                     Stroke=&quot;{DynamicResource ListItemSelectedBorderBrush}&quot; /&gt;
                          &lt;Rectangle x:Name=&quot;BackgroundGradientSelected&quot;
                                     Fill=&quot;{DynamicResource PressedBrush}&quot;
                                     Opacity=&quot;0&quot;
                                     RadiusX=&quot;1&quot;
                                     RadiusY=&quot;1&quot;
                                     Stroke=&quot;{DynamicResource PressedBorderBrush}&quot;
                                     StrokeThickness=&quot;1&quot; /&gt;
                          &lt;ContentPresenter x:Name=&quot;contentPresenter&quot;
                                        Margin=&quot;{TemplateBinding Padding}&quot;
                                        HorizontalAlignment=&quot;{TemplateBinding HorizontalContentAlignment}&quot;
                                        Content=&quot;{TemplateBinding Content}&quot;
                                        ContentTemplate=&quot;{TemplateBinding ContentTemplate}&quot; /&gt;
                      &lt;/Grid&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource OutsideFontColor}&quot; /&gt;
  &lt;/Style&gt;
  </code></pre>
  <h1>My DataTemplate</h1>
  <pre><code>&lt;DataTemplate x:Key=&quot;centralTile&quot;&gt;
      
      &lt;StackPanel Width=&quot;80&quot;
                  Height=&quot;40&quot;
                  KeyboardNavigation.AcceptsReturn=&quot;True&quot;&gt;
          &lt;StackPanel.InputBindings&gt;
              &lt;KeyBinding Key=&quot;Enter&quot; Command=&quot;{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}&quot; CommandParameter=&quot;{Binding}&quot;&gt;&lt;/KeyBinding&gt;
          &lt;/StackPanel.InputBindings&gt;
          &lt;Grid&gt;              
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width=&quot;30&quot; /&gt;
                  &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Button Command=&quot;{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}&quot;
                              CommandParameter=&quot;{Binding}&quot;&gt;
                  &lt;TextBlock Text=&quot;{Binding Path=Name}&quot; /&gt;
              &lt;/Button&gt;
              &lt;Image Grid.Column=&quot;1&quot; Source=&quot;Water lilies.jpg&quot; /&gt;
          &lt;/Grid&gt;
          &lt;TextBlock HorizontalAlignment=&quot;Center&quot;
                     FontSize=&quot;13&quot;
                     Text=&quot;{Binding Path=Name}&quot; /&gt;
      &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  <p>I Cant Seem to find a way to do it...</p>
  <p>I attached my InputBinding in DataTemplate as well has in Style Nothing Works</p>
  <pre><code>            &lt;KeyBinding Key=&quot;Enter&quot; Command=&quot;{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}&quot; CommandParameter=&quot;{Binding}&quot;&gt;&lt;/KeyBinding&gt; 
  </code></pre>