title: context menu for removing items in listview
body: <p>I have a ListView which displays a list of string values. I want to add a context menu entry for each item in the list to remove the selected item. My XAML looks like this:</p>
  
  <pre><code>&lt;ListView x:Name="itemsListView" ItemsSource="{Binding MyItems}"&gt;
    &lt;ListView.ContextMenu&gt;
      &lt;ContextMenu&gt;
        &lt;MenuItem Header="Remove"
                  Command="{Binding RemoveItem}"
                  CommandParameter="{Binding ElementName=itemsListView, Path=SelectedItem}" /&gt;
      &lt;/ContextMenu&gt;
    &lt;/ListView.ContextMenu&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>The problem is that the <code>CommandParameter</code> value is always null. I've added an additional button to remove the selected item to check if my command works. The button has exactly the same binding and removing items via the button works. The button looks like this:</p>
  
  <pre><code>&lt;Button Content="Remove selected item"
          Command="{Binding RemoveItem}"
          CommandParameter="{Binding ElementName=itemsListView, Path=SelectedItem}"/&gt;
  </code></pre>
  
  <p>The command looks like this:</p>
  
  <pre><code>private ICommand _removeItem;
  
  public ICommand RemoveItem
  {
    get { return _removeItem ?? (_removeItem = new RelayCommand(p =&gt; RemoveItemCommand((string)p))); }
  }
  
  private void RemoveItemCommand(string item)
  {
    if(!string.IsNullOrEmpty(item))
      MyItems.Remove(item);  
  
  }
  </code></pre>
  
  <p>Any ideas why the selected item is null when opening the context menu? Maybe a focus problem of the listview?</p>