title: In WPF, How to get a Command Parameter from a specific item in a Collection View Source that is bound to a ListView?
body: <p>My Goal: Right click on a specific item in my ListView, a context menu pops up, select a command, followed by me running a function based on which item's context menu was selected.</p>
  
  <p>My ListView's ItemsSource is bounded to a CollectionViewSource, whose source is an ObservableCollection of "Items". 
  (ListView, binds -> CollectionViewSource, source -> ObservableCollection of class "Item")</p>
  
  <p>What I tried to do is add a general ContextMenu to all of the "Items" in the listview, and when the context menu item is selected for an item in the ListView, then a command is run. I was able to get the command to run in general, but I haven't been able to get any information/parameters about the specific item whose context menu was chosen. </p>
  
  <p>In this example, "Item" class has a string called host, and I want to pass host string to the RefundRequestCommand but I havent been able to pass any CommandParameters.</p>
  
  <p>I've read some stuff about creating a data template and using that, but haven't been successful. Can anyone guide me / help me out?</p>
  
  <p>Here is some code for reference:</p>
  
  <p>ListView:</p>
  
  <pre><code>&lt;ListView x:Name="ordersList" Margin="0,10,10,0" BorderThickness="2" Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Stretch" ItemsSource="{Binding Source={StaticResource cvsOrders}}" SelectionChanged="ordersList_SelectionChanged" SelectedIndex="0" SelectionMode="Extended"&gt;
              &lt;ListView.Resources&gt;
                  &lt;local:RefundRequestCommand x:Key="refund"&gt;&lt;/local:RefundRequestCommand&gt;
              &lt;/ListView.Resources&gt;
              &lt;ListView.ContextMenu&gt;
                  &lt;ContextMenu&gt;
                      &lt;MenuItem Header="test" Command="{StaticResource refund}" CommandParameter="{Binding host}"&gt;&lt;/MenuItem&gt;
                  &lt;/ContextMenu&gt;
              &lt;/ListView.ContextMenu&gt;
              &lt;ListView.View&gt;
                  &lt;GridView&gt;
                      &lt;GridViewColumn Width="140"&gt;
                          &lt;GridViewColumnHeader Name="OrderNumber" Click="sortClick" Tag="orderNumber" Content="Order Number" /&gt;
                          &lt;GridViewColumn.CellTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;TextBlock Text="{Binding orderNumber}" TextAlignment="Center"/&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/GridViewColumn.CellTemplate&gt;
                      &lt;/GridViewColumn&gt;
          //On and On.....
  </code></pre>
  
  <p>Command:</p>
  
  <pre><code>class RefundRequestCommand : ICommand
  {
      TreeViewFilter treeViewFilter;
  
      public void Execute(object parameter)
      {
          string host = (string)parameter;
          Console.WriteLine(host);  //FOR TESTING
      }
  
      public bool CanExecute(object parameter)
      {
          return true;
      }
  
      public event EventHandler CanExecuteChanged;
  }
  </code></pre>