title: CommandParameter not passed to CanExecute when databound within a DataGrid (CanExecute parameter is null)
body: <p>I am using the <a href="https://www.nuget.org/packages/Microsoft.Toolkit.Mvvm/" rel="nofollow noreferrer">Microsoft.Toolkit.Mvvm</a> nuget package for building out a WPF application on .NET Core 3.1.</p>
  <p>I'm having an issue with binding the CommandParameter of a button within a DataGridTemplateColumn of a Datagrid.</p>
  <p>I have a RelayCommand defined on my viewmodel, using IRelayCommand, and have a CanExecute method defined that takes a parameter. I then have the CommandParameter of the button binding bound to the data of the datagrid row.</p>
  <p>During runtime, I am seeing the CanExecute method called for every row of my datagrid, however the parameter value is always null. If I have 5 items in my ObservableCollection, I see CanExecute called 5 times, 3 items... 3 times. In all cases the value is null.</p>
  <p>Below is the code for my viewmodel that creates an ObservableCollection of TestModel types. A RelayCommand is created, and the criteria of the CanExecute is dumbed down to just comparing the name property of the databound model.</p>
  <p>What I'd expect here is that for all rows except the row with name &quot;Test2&quot;, the bound button would be enabled. The button in Test2's row would be disabled.</p>
  <p>Here is my viewmodel, and related model class.</p>
  <pre><code>public class MainWindowVM : ObservableObject, IViewModel
  {
      public MainWindowVM()
      {
          TestData = new ObservableCollection&lt;TestModel&gt;
          {
              new TestModel() {Name = &quot;Test1&quot;},
              new TestModel() {Name = &quot;Test2&quot;},
              new TestModel() {Name = &quot;Test3&quot;}
          };
  
          DeleteCommand = new RelayCommand&lt;TestModel&gt;(Delete, CanDelete);
      }
  
      public IRelayCommand&lt;TestModel&gt; DeleteCommand { get; }
  
      private void Delete(TestModel model)
      {
          //do stuff
      }
  
      private bool CanDelete(TestModel model)
      {
          if (model.Name == &quot;Test2&quot;)
          {
              return false;
          }
          return true;
      }
  
      public ObservableCollection&lt;TestModel&gt; TestData
      {
          get =&gt; _testData;
          set =&gt; SetProperty(ref _testData, value);
      }
      private ObservableCollection&lt;TestModel&gt; _testData;
  }
  
  public class TestModel : ObservableObject
  {
      public string Name
      {
          get =&gt; _name;
          set =&gt; SetProperty(ref _name, value);
      }
      private string _name;
  }
  </code></pre>
  <p>And my xaml for the Datagrid</p>
  <pre><code>&lt;Grid&gt;
      &lt;DataGrid ItemsSource=&quot;{Binding Path=TestData}&quot; AutoGenerateColumns=&quot;False&quot;&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header=&quot;Username&quot;
                                  Binding=&quot;{Binding Path=Name}&quot;
                                  MinWidth=&quot;180&quot; /&gt;
  
              &lt;DataGridTemplateColumn Header=&quot;&quot; Width=&quot;160&quot;&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
  
                              &lt;Button Command=&quot;{Binding Path=DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}&quot;
                                      CommandParameter=&quot;{Binding}&quot;  Content=&quot;Delete&quot;
                                      Width=&quot;100&quot;   &gt;
                              &lt;/Button&gt; 
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  <p>What am I missing here?
  I've used this approach countless times in other WPF applications. This is my first time using this toolkit (I've used MVVMLight previously), and the first time building WPF on .NET Core.
  Is this a change in WPF on .NET Core? Something different between the two MVVM toolkits?</p>
  <p>Any help or direction you can provide would be much appreciated, thank you.</p>