title: WPF Input KeyBinding for a ListBox Item
body: <p>I'm having a WPF Application, programatically I'm setting the focus to the ListBox Item, after that using <strong>UP / Down arrow</strong> I'm navigating from one Item to another Item. I need to Implement <strong><code>ENTER Key</code>Event</strong> for that appropriate Item, it should trigger the <strong><code>ICommand</code></strong> <code>SelectItemCommand</code> in the ViewModel.</p>
  
  <p>Consider the ViewModel Code:</p>
  
  <pre><code>public class MobileViewModel
  {
      public ObservableCollection&lt;Mobile&gt; MobileCollection { get; set; }
  
      public MobileViewModel()
      {
          MobileCollection = new ObservableCollection&lt;Mobile&gt;()
          {
              new Mobile() { ID = 1, Name = "iPhone 6S", IsSelected = false },
              new Mobile() { ID = 2, Name = "Galaxy S7", IsSelected = false }                        
          }
      }
  
      public ICommand SelectItemCommand
      {
          get
          {
              return new DelegatingCommand((obj) =&gt;
              {
                  // Enter Key Event Operation
              });
          }
      }
  
  }
  
  public class Mobile
  {
      public int ID { get; set; }
      public string Name { get; set; }
      public bool IsSelected { get; set; }
  }
  </code></pre>
  
  <p>The XAML Code is</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding MobileCollection}" x:Name="KeyListBox"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Button Command="{Binding SelectItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MobileViewModel}}}" CommandParameter="{Binding }"&gt;
                  &lt;Button.InputBindings&gt;
                      &lt;KeyBinding Key="Enter" Command="{Binding SelectItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MobileViewModel}}}" CommandParameter="{Binding }" /&gt;
                  &lt;/Button.InputBindings&gt;
                  &lt;Button.Content&gt;
                          &lt;StackPanel&gt;
                              &lt;TextBlock Text="{Binding Name}" /&gt;
                          &lt;/StackPanel&gt;
                  &lt;/Button.Content&gt;
              &lt;/Button&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>My requirement is to trigger the ICommand while on Keyboard ENTER Key hit. I tried the KeyBinding inside the Button, but its not happening. Kindly assist me.</p>