title: Why does my command binding for my button not work?
body: <p>The problem that I have is getting my button to work with the binding. I'm not sure what to set the DataContext. I am getting this error with my binding:</p>
  
  <p><code>System.Windows.Data Error: 40 : BindingExpression path error: 'ClickMeCommand' property not found on 'object' ''Person' (HashCode=13029119)'. BindingExpression:Path=ClickMeCommand; DataItem='Person' (HashCode=13029119); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')</code></p>
  
  <p>What I'm doing here is I have a ListView in XAML and I have a Grid View with three columns. One column stores Name from the Person object, the second column stores Date from the Person object, and the third column is the same for everything on the list, a button. When the button is clicked, I want to execute a command to remove the task from my observable collection and update the list. I know how to do that but I can't get the binding command for the button to work.</p>
  
  <pre><code>&lt;ListView x:Name="List" HorizontalAlignment="Left" Margin="0,0,0,-2"` Width="292" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Height="Auto"&gt;
                      &lt;ListView.ItemContainerStyle&gt;
                          &lt;Style TargetType="{x:Type ListViewItem}"&gt;
                              &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt;
                      &lt;/Style&gt;
                  &lt;/ListView.ItemContainerStyle&gt;
                  &lt;ListView.View&gt;
                      &lt;GridView&gt;
                          &lt;GridView.ColumnHeaderContainerStyle&gt;
                              &lt;Style BasedOn="{StaticResource {x:Type GridViewColumnHeader}}" TargetType="{x:Type GridViewColumnHeader}"&gt;
                                  &lt;Setter Property="IsHitTestVisible" Value="False"/&gt;
                              &lt;/Style&gt;
                          &lt;/GridView.ColumnHeaderContainerStyle&gt;
                          &lt;GridViewColumn x:Name="Column1" Header="Assignment" DisplayMemberBinding="{Binding Name}" Width="190"/&gt;
                          &lt;GridViewColumn x:Name="Column2" Header="Date" DisplayMemberBinding="{Binding Date}" Width="45"/&gt;
                          &lt;GridViewColumn Header="Edit" Width="35" CellTemplate="{StaticResource editColumnTemplate}"&gt;
                          &lt;/GridViewColumn&gt;
                      &lt;/GridView&gt;
                  &lt;/ListView.View&gt;
              &lt;/ListView&gt;
  
  
  &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="editColumnTemplate"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;Button x:Name="deleteButton" Content="X"  Command="{Binding Path=ClickMeCommand}" HorizontalAlignment="Stretch"/&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>//</p>
  
  <pre><code>private class Person
          {
              public String Name { get; set; }
              public String Date { get; set; }
  
          }
  </code></pre>
  
  <p>In my code behind, I create a new tab and add a listview in it. Everytime I add a new person, it would add a line in the list with his/her name / date and a button on the third column. </p>
  
  <pre><code> public MainWindow(){
       InitializeComponent();
       this.DataContext = new MainViewModel();
  }
  TabItem newItem = new TabItem();
  ListView newList = new ListView();
  ObservableCollection&lt;TabItem&gt; newSource = new ObservableCollection&lt;TabItem&gt;();
  newList.ItemsSource = newSource;
  TabControl.Items.Add(newItem);
  </code></pre>
  
  <p>That button is binded to the command ClickMeCommand as you can see from above. This is the class:</p>
  
  <pre><code> public class MainViewModel
  {
      public MainViewModel()
      {
  
      }
  
      private ICommand clickMeCommand;
      public ICommand ClickMeCommand
      {
          get
          {
              if (clickMeCommand == null)
                  clickMeCommand = new RelayCommand(i =&gt; this.ClickMe(), null);
              return clickMeCommand;
          }
      }
  
      private void ClickMe()
      {
          MessageBox.Show("You Clicked Me");
      }
  }    
  public class RelayCommand : ICommand
  {
      readonly Action&lt;object&gt; execute;
      readonly Predicate&lt;object&gt; canExecute;
  
      public RelayCommand(Action&lt;object&gt; executeDelegate, Predicate&lt;object&gt; canExecuteDelegate)
      {
          execute = executeDelegate;
          canExecute = canExecuteDelegate;
      }
  
      bool ICommand.CanExecute(object parameter)
      {
          return canExecute == null ? true : canExecute(parameter);
      }
  
      event EventHandler ICommand.CanExecuteChanged
      {
          add { CommandManager.RequerySuggested += value; }
          remove { CommandManager.RequerySuggested -= value; }
      }
  
      void ICommand.Execute(object parameter)
      {
          execute(parameter);
      }
  }
  </code></pre>