title: How to get all the rows from DataGrid in WPF
body: <p>I have a DataGrid in my WPF application, I want to get all the row values in a list in a button click. I tried some ways but I get the last row values only...</p>
  
  <pre><code>private async void Save_Btn_Click(object sender, RoutedEventArgs e)
  {
      pojo rowdata = new pojo();
      int rowcount = calendarmstrDG.Items.Count;
      List&lt;pojo&gt; pojolist = new List&lt;pojo&gt;();
      var rows = (calendarmstrDG).SelectedItems;
      for (int i = 1; i &lt; rowcount - 1; i++)
      {
          pojo sda = (pojo)calendarmstrDG.SelectedItems;
          pojolist.Add(sda);
      }
  }
  </code></pre>
  
  <p>Here calendarmstrDG is my datagrid name ...
  pojo is my model class name ...</p>
  
  <pre><code>public class pojo
  {
      public string Prefix { get; set; }
      public int Year { get; set; }
      public int Quarter { get; set; }
      public int SerialNo { get; set; }
      public string From { get; set; }
      public string To { get; set; }
      public string PeriodName { get; set; }
  }
  </code></pre>