title: How to refresh/reload datagrid in WPF?
body: <p>I want to implement a datagrid, which will be filled every 5min. </p>
  
  <p>But, first code: 
  XAML:</p>
  
  <pre><code>    &lt;Window.Resources&gt;
      &lt;ObjectDataProvider x:Key="_employeeProvider" ObjectType="{x:Type Brw1:EmployeeDataProvider}" /&gt;
      &lt;ObjectDataProvider x:Key="_employeeFactory" ObjectInstance="{StaticResource _employeeProvider}" MethodName="GetEmployees" /&gt;
  &lt;/Window.Resources&gt;
  
  &lt;Grid DataContext="{Binding Source={StaticResource _employeeFactory}}"&gt;
      &lt;DataGrid Name="_employeeDataGrid" DockPanel.Dock="Top" Margin="12,57,12,0" VerticalAlignment="Top" ItemsSource="{Binding}" AutoGenerateColumns="True"&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>    public class EmployeeDataProvider
  {
      public ObservableEmployee GetEmployees()
      {
          // This is only example
          // In my project right here I will get data from database, put into the list, and fill datagrid with it. 
          List&lt;UIEmployee&gt; list = new List&lt;UIEmployee&gt;
                  {
                      new UIEmployee { Id = 1, FirstName = "Prajeesh2", LastName = "Prathap", Occupation = "Engineer", DateOfJoining=new DateTime(2005, 8, 1), IsContracter = false, AddressInfo = null },
                      new UIEmployee { Id = 2, FirstName = "Rahul2", LastName = "Bose", Occupation = "Student", DateOfJoining=new DateTime(2009, 5, 4), IsContracter = true, AddressInfo = null },
                      new UIEmployee { Id = 3, FirstName = "Steve2", LastName = "Roberts", Occupation = "Manager", DateOfJoining=new DateTime(1994, 8, 23), IsContracter = false, AddressInfo = null },
                      new UIEmployee { Id = 4, FirstName = "Micheal2", LastName = "Clarke", Occupation = "Engineer", DateOfJoining=new DateTime(2003, 1, 14), IsContracter = true, AddressInfo = null },
                      new UIEmployee { Id = 5, FirstName = "Rachel2", LastName = "Green", Occupation = "Professional", DateOfJoining=new DateTime(2006, 3, 8), IsContracter = true, AddressInfo = null }
                  };
  
          ObservableEmployee employeeCollection = new ObservableEmployee(list);
          return employeeCollection;
      }
  }
  </code></pre>
  
  <p>It is very simple. Datagrid use <code>GetEmployees()</code> method to get data.</p>
  
  <p>What I try to do, is to run GetEmployess every 5min.. </p>
  
  <p>PS. <code>_employeeDataGrid.Items.Refresh();</code> - doesn't work. </p>
  
  <p>UPDATE: </p>
  
  <p>Missing classes: </p>
  
  <pre><code>    public class ObservableEmployee : ObservableCollection&lt;UIEmployee&gt;
  {
      public ObservableEmployee(IEnumerable&lt;UIEmployee&gt; employees) : base(employees) { }
  }
  
  public class UIEmployee// : INotifyPropertyChanged
  {
      private int m_Id;
      public int Id
      {
          get { return m_Id; }
          set
          {
              m_Id = value;
          }
      }
  
      private string m_FirstName;
      public string FirstName
      {
          get { return m_FirstName; }
          set
          {
              m_FirstName = value;
          }
      }
  
      private string m_LastName;
      public string LastName
      {
          get { return m_LastName; }
          set
          {
              m_LastName = value;
          }
      }
  
      private string m_Occupation;
      public string Occupation
      {
          get { return m_Occupation; }
          set
          {
              m_Occupation = value;
          }
      }
  
      private DateTime m_DateOfJoining;
      public DateTime DateOfJoining
      {
          get { return m_DateOfJoining; }
          set
          {
              m_DateOfJoining = value;
          }
      }
  
      private bool m_IsContracter;
      public bool IsContracter
      {
          get { return m_IsContracter; }
          set
          {
              m_IsContracter = value;
          }
      }
  
  }
  </code></pre>
  
  <p>UPDATE2: 
  I need something, that will reload datagrid, so datagrid will have to use <code>GetEmployees</code> method again.</p>
  
  <p><strong>UPDATE3:</strong></p>
  
  <pre><code>public class TaskDataProvider
  {
      static ObservableEmployee list = new ObservableEmployee();
      static DataRepository dr = new DataRepository();
  
      public static ObservableEmployee GetEmployees()
      {
          UpdateMyList();
          return list;
      }
  
      public static void UpdateMyList() 
      {
          ObservableTask newList = new ObservableTask(dr.GetTasks());
  
          list.Clear();
          foreach (Task t in newList)
          {
              list.Add(t);
          }
      }
  }
  </code></pre>
  
  <p>This at start works. 
  But that, I change sth in database, and click the button which do:</p>
  
  <pre><code>TaskDataProvider.UpdateMyList();
  </code></pre>
  
  <p>And on  break point, it's gets right data (new data) - but, datagrid is not refreshing:/</p>