title: WPF DataGridCellInfo Item property value for DatePicker column
body: <p>In the following <code>WPF DataGrid</code>, the following code successfully returns the value of the cell in the first column of the selected row.</p>
  <p>For the first cell, the data item <a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagridcellinfo.item?view=netcore-3.1#System_Windows_Controls_DataGridCellInfo_Item" rel="nofollow noreferrer">DataGridCellInfo.Item</a> below is a TextBlock (default):</p>
  <pre><code>DataGridCellInfo cellInfo = dgEvents.SelectedCells[0]; //cell in first column in selected row
  string sSubject = (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBlock).Text;
  </code></pre>
  <p><strong>Question</strong>: What should be the data item <code>cellInfo.Item</code> below? The cell does have a date value but I'm getting the error: <code>cellInfo_1.Column.GetCellContent(cellInfo_1 .Item) as DatePicker returns null</code></p>
  <pre><code>DataGridCellInfo cellInfo_1 = dgEvents.SelectedCells[1]; //cell in second column in selected row
  DateTime? mydatetime = (cellInfo_1.Column.GetCellContent(cellInfo_1 .Item) as DatePicker).SelectedDate;
  </code></pre>
  <p><strong>Remark</strong>: Please note that the question is about to get the new date value selected in the cell, and NOT about the old value the cell was already bound to.</p>
  <p><strong>XAML</strong>:</p>
  <pre><code>&lt;Window x:Class=&quot;MyWPFProject.DataGrid_control.DataGridColumnsSample&quot;
          xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
          Title=&quot;DataGridColumnsSample&quot; Height=&quot;200&quot; Width=&quot;300&quot;&gt;
      &lt;Grid Margin=&quot;10&quot;&gt;
          &lt;DataGrid Name=&quot;dgUsers&quot; AutoGenerateColumns=&quot;False&quot;&gt;
              &lt;DataGrid.Columns&gt;
  
                  &lt;DataGridTextColumn Header=&quot;Name&quot; Binding=&quot;{Binding Name}&quot; /&gt;
  
                  &lt;DataGridTemplateColumn Header=&quot;Birthday&quot;&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;DatePicker SelectedDate=&quot;{Binding Birthday}&quot; BorderThickness=&quot;0&quot; /&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
  
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>