title: Pass parameter via context menu to DevExpress TreeListControl
body: <p>I have a TreeListControl and I will like to pass the selected row as parameter on my context menu. So my control looks like:</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code>&lt;Window x:Class="WpfApplication2.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525" 
          xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/grid" &gt;
  
      &lt;dxt:TreeListControl Name="treeList" ItemsSource="{Binding MyCollection}"&gt;
  
          &lt;!-- Context menu I AM HAVING TROUBLE HERE PASSING A PARAMETER TO THE COMMAND --&gt;
          &lt;dxt:TreeListControl.ContextMenu&gt;
              &lt;ContextMenu&gt;
                  &lt;MenuItem Header="Mount"
                      Command="{Binding MyCustomCommand}"   
                      CommandParameter="{Binding SELECTED_JUST_CLICKED_ROW_OF_THIS_CONTROL}"&gt;
                      &lt;MenuItem.Icon&gt;
                          &lt;Image Source="/Server;component/Images/SomeImage.png" Width="40"  /&gt;
                      &lt;/MenuItem.Icon&gt;
                  &lt;/MenuItem&gt;
              &lt;/ContextMenu&gt;
          &lt;/dxt:TreeListControl.ContextMenu&gt;
  
          &lt;!-- Columns of the control --&gt;
          &lt;dxt:TreeListControl.Columns&gt;                     
              &lt;dxt:TreeListColumn FieldName="Name" Header="Name"/&gt;
              &lt;dxt:TreeListColumn FieldName="Position" Header="Position"/&gt; 
          &lt;/dxt:TreeListControl.Columns&gt;
          &lt;!-- View --&gt;
          &lt;dxt:TreeListControl.View&gt;
              &lt;dxt:TreeListView Name="treeListView1" AutoWidth="True"
                                KeyFieldName="ID" ParentFieldName="ParentID"/&gt;
          &lt;/dxt:TreeListControl.View&gt;
      &lt;/dxt:TreeListControl&gt;
  
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code Behind</strong></p>
  
  <pre><code>using System.Collections.Generic;
  using System.Windows;
  using System.Windows.Documents;
  
  namespace WpfApplication2
  {
      public partial class MainWindow : Window
      {        
          // Properties that are binded on View
          public ObservableCollection&lt;Employee&gt; MyCollection {get;set;}
          public MyCommand MyCustomCommand { get; set; }
  
          public MainWindow ( )
          {
              InitializeComponent( );
  
              // init properties
              MyCollection = new ObservableCollection&lt;Employee&gt;();
              MyCustomCommand = new MyCommand();
  
              // bind properties to view
              this.DataContext = this;
  
              // add items to observable collection
              foreach(var employee in GetStuff() )
                   MyCollection.Add( employee );              
          }
  
          // generate employees
          public static List&lt;Employee&gt; GetStuff ( )
          {
              List&lt;Employee&gt; stuff = new List&lt;Employee&gt;( );
  
              stuff.Add( new Employee() { ID = 2 , ParentID = 0 , Name = "Irma R. Marshall" } );    
              stuff.Add( new Employee() { ID = 6 , ParentID = 2 , Position = "Brian C. Cowling" } );
              stuff.Add( new Employee() { ID = 7 , ParentID = 2 , Position = "Thomas C. Dawson" } );                                        
              return stuff;
          }        
      }
  }
  
  public class Employee
  {
      public int ID { get; set; }
      public int ParentID { get; set; }
      public string Name { get; set; }
      public string Position { get; set; }
  }
  
  public class MyCommand : ICommand
  {                
      public bool CanExecute ( object parameter )
      {
          // Here I want parameter to be selected ROW!!!!
          return true;
      }
  
      public event EventHandler CanExecuteChanged;
  
      public void Execute ( object parameter )
      {
          // Here I want parameter = selected row !!!!
  
          // based on value of parameter perform logic
      }
  }
  </code></pre>
  
  <p>Everything works but the CommandParameter. I have tried things like:</p>
  
  <pre><code>CommandParameter="{Binding RowHandle.Value}"
  CommandParameter="{Binding Data.Name}"
  CommandParameter="{Binding Data}"
  CommandParameter="{Binding ElementName=treeList, Path=Name}"
  </code></pre>
  
  <p>all of them return null... The only parameter I have been able to pass is:</p>
  
  <pre><code>CommandParameter="Foo"
  </code></pre>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p><strong>DevExpress answered the question at:  <a href="http://www.devexpress.com/Support/Center/Question/Details/Q473660" rel="nofollow">http://www.devexpress.com/Support/Center/Question/Details/Q473660</a></strong></p>