title: How do I refresh a WPF DataGrid
body: <p>I have a <code>DataGrid</code> with bound <code>ItemsSource</code>:</p>
  
  <pre><code>&lt;DataGrid
      x:Name="grid"
      FlowDirection="RightToLeft"
      AutoGenerateColumns="False"
      ItemsSource="{Binding ListGuards}"
      IsReadOnly="True"&gt;
  </code></pre>
  
  <p>Columns definition (One example):<br></p>
  
  <pre><code>&lt;DataGridTextColumn Header="ID" Binding="{Binding Id}" /&gt;
  </code></pre>
  
  <p>Code-behind:</p>
  
  <pre><code>public ObservableCollection&lt;TableGuard&gt; ListGuards { get; set; }
  public C'tor(...) {
      ListGuards = new ObservableCollection&lt;TableGuard&gt;(s); //s = List&lt;TableGuard&gt;
      this.DataContext = this;
  }
  </code></pre>
  
  <p>Submitting data:</p>
  
  <pre><code>private void submit(object sender, RoutedEventArgs e) {
          if (list == null)
              list = new List&lt;TableGuard&gt;();
  
          TableGuard guard = new TableGuard();
          guard.FName = fName.Text;
          guard.LName = lName.Text;
          guard.Id = int.Parse(id.Text);
          guard.WorkPlace = workPlace.Text;
          guard.LastTraining = lastTraining.Text;
          guard.NextTraining = nextTraining.Text;
          guard.Birthday = birthDay.Text;
          guard.TrainingType = trainingType.Text;
  
          bool exists = false;
          foreach (var g in list)
              if (guard.Id == g.Id) {
                  exists = true;
                  break;
              }
  
          if (exists)
              MessageBox.Show("ID EXISTS!");
          else if (id.Text.Length &lt; 9)
              MessageBox.Show("ID NEEDS TO BE 9 DIGITS!");
          else {
              if (isEdit) {
                  jsonObj[selectedRow]["Id"] = guard.Id;
                  jsonObj[selectedRow]["FName"] = guard.FName;
                  jsonObj[selectedRow]["LName"] = guard.LName;
                  jsonObj[selectedRow]["Birthday"] = guard.Birthday;
                  jsonObj[selectedRow]["LastTraining"] = guard.LastTraining;
                  jsonObj[selectedRow]["NextTraining"] = guard.NextTraining;
                  jsonObj[selectedRow]["WorkPlace"] = guard.WorkPlace;
                  jsonObj[selectedRow]["TrainingType"] = guard.TrainingType;
                  File.WriteAllText(path, JsonConvert.SerializeObject(jsonObj));
                  Close();
              } else {
                  list.Add(guard);
                  File.WriteAllText(path, JsonConvert.SerializeObject(list));
                  Close();
              }
          }
      }
  </code></pre>
  
  <p>I wish to refresh the <code>DataGrid</code> after I edit some data. How do I do it?</p>