title: Passing Command Parameters
body: <p>I'm trying to pass a command parameter with my command. I have commands in general working but passing a parameter doesn't seem to be going to well for me.</p>
  
  <p>I'm trying to pass the UserName Property from the Hierarchical Data in my XAML. What am I doing wrong here.</p>
  
  <p>I recieve and error trying to compile with the commands statement:</p>
  
  <p><em>cannot convert from 'lambda expression' to 'System.Action'</em></p>
  
  <pre><code>&lt;HierarchicalDataTemplate 
      DataType="{x:Type viewModel:UsersViewModel}" 
      ItemsSource="{Binding Children}"&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;TextBlock Text="{Binding UserName}"&gt;
              &lt;TextBlock.ContextMenu&gt;
                      &lt;ContextMenu&gt;
                          &lt;MenuItem Header="Edit" Command="{Binding EditCommand}" CommandParameter="{Binding UserName}"/&gt;
                          &lt;MenuItem Header="Delete"/&gt;
                      &lt;/ContextMenu&gt;
                  &lt;/TextBlock.ContextMenu&gt;
          &lt;/TextBlock&gt;
      &lt;/StackPanel&gt;
  &lt;/HierarchicalDataTemplate&gt;
  </code></pre>
  
  
  
  <pre><code>private RelayCommand _editCommand;
      public ICommand EditCommand
      {
          get
          {
              if (_editCommand== null)
              {
                  _editCommand= new RelayCommand(param =&gt; this.LoadUser(object parameter));
              }
              return _editCommand;
          }
      }
  
      public void LoadUser(object username)
      {
  
      } 
  </code></pre>
  
  <p><strong>RelayCommand Class</strong></p>
  
  <pre><code>public class RelayCommand : ICommand
  {
      #region Fields
  
      readonly Action&lt;object&gt; _execute;
      readonly Predicate&lt;object&gt; _canExecute;
  
      #endregion // Fields
  
      #region Constructors
  
      public RelayCommand(Action&lt;object&gt; execute)
          : this(execute, null)
      {
      }
  
      public RelayCommand(Action&lt;object&gt; execute, Predicate&lt;object&gt; canExecute)
      {
          if (execute == null)
              throw new ArgumentNullException("execute");
  
          _execute = execute;
          _canExecute = canExecute;
      }
      #endregion // Constructors
  
      #region ICommand Members
  
      [DebuggerStepThrough]
      public bool CanExecute(object parameter)
      {
          return _canExecute == null ? true : _canExecute(parameter);
      }
  
      public event EventHandler CanExecuteChanged
      {
          add { CommandManager.RequerySuggested += value; }
          remove { CommandManager.RequerySuggested -= value; }
      }
  
      public void Execute(object parameter)
      {
          _execute(parameter);
      }
      #endregion
  }
  </code></pre>
  
  <p>Thanks for the help!</p>