title: ListBox item in command
body: <p>I am trying to get the Listboxitem when the user clicks on the button. But in my command the item is always null. Please help to get the item in my command</p>
  
  <pre><code>    &lt;DataTemplate x:Key="MyTemplate"&gt;
          &lt;Grid ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="5" &gt;                  
              &lt;Button Command="{Binding MyCommand}" CommandParameter="{Binding ElementName=lb, Path=SelectedItem}"&gt;
              &lt;/Button&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  
      &lt;ListBox Name="lb" Grid.Row="1"
              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
              ItemsSource="{Binding MyItemsList}"  
              Margin="5"
              HorizontalContentAlignment="Stretch" 
              ItemTemplate="{StaticResource MyTemplate}" /&gt;
  </code></pre>
  
  <p>ViewModel code</p>
  
  <pre><code>    public ICommand MyCommand
      {
          get
          {
              if (_MyCommand == null)
                  _MyCommand = new RelayCommand(o =&gt; MyCommand_Execute(o));
              return _MyCommand;
          }
      }
  
      private void MyCommand_Execute(object item)
      {
        //           item is always null
      }
  </code></pre>