title: DataGrid refresh not working when I use method from another class
body: <p>I have a method to refresh my <code>DataGrid</code> after add/edit/delete data.</p>
  
  <pre><code>public void EmployeesDbConnection&lt;T&gt;(T dbset, string collectionName, Page page) where T : class
  {
      CompanyManagerContext db = new CompanyManagerContext();
  
      var collectionViewSource = page.FindResource(collectionName) as CollectionViewSource;
  
      db.Set&lt;T&gt;().Load();
      collectionViewSource.Source = db.Set&lt;T&gt;().Local;
      collectionViewSource.View.Refresh();
  }
  </code></pre>
  
  <p>My problem is that my method is working only when I use it in the same window/page, where my datagrid is.</p>
  
  <p>A scenario is:</p>
  
  <p>I have <code>DataGrid</code> in EmployeePage.
  I have <strong>Add</strong> <code>Button</code> in EmployeePage.</p>
  
  <p>When I click <strong>Add</strong> <code>Button</code>, on display it shows a new <code>Window</code> (AddEmployeeWindow) with  fields to enter the employee data e.g (name, lastname, birthdate etc) and add, reset and cancel buttons.</p>
  
  <p>When I click the <strong>Add</strong> <code>Button</code>, my data inserts to database but <code>DataGrid</code> won't refresh.</p>
  
  <p>When I am doing the same thing in employee page it refreshes.</p>
  
  <p>In EmployeePage I run a method like this(<code>DataGrid</code> is refreshing):</p>
  
  <pre><code>dbManagement.EmployeesDbConnection(newEmployee, "CollectionViewSource", this);
  </code></pre>
  
  <p>In AddWindow I run method like this(<code>DataGrid</code> is not refreshing):</p>
  
  <pre><code>dbManagement.EmployeesDbConnection(newEmployee, "CollectionViewSource",     empPage);
  </code></pre>
  
  <p>with </p>
  
  <pre><code>readonly EmployeePages empPage = new EmployeePages();
  </code></pre>
  
  <p>Its XAML code of bindings:</p>
  
  <pre><code>&lt;Page.Resources&gt;
      &lt;CollectionViewSource x:Key="CollectionViewSource" d:DesignSource="{d:DesignInstance {x:Type models:Employee}, CreateList=True}"&gt;&lt;/CollectionViewSource&gt;
  &lt;/Page.Resources&gt;
  &lt;DataGrid x:Name="EmployeesDataGrid" HorizontalAlignment="Left" Margin="10,355,0,0" VerticalAlignment="Top" Height="305" Width="880"
                    DataContext="{StaticResource CollectionViewSource}" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}"
                    RowDetailsVisibilityMode="VisibleWhenSelected" IsReadOnly="True"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn x:Name="IdColumn" Header="Id" Binding="{Binding Id}"/&gt;
          &lt;DataGridTextColumn x:Name="FirstNameColumn" Header="First Name" Binding="{Binding FirstName}"/&gt;
          &lt;DataGridTextColumn x:Name="LastNameColumn" Header="Last Name" Binding="{Binding LastName}"/&gt;
          &lt;DataGridTextColumn x:Name="MobilePhoneNumberColumn" Header="Mobile Phone" Binding="{Binding MobilePhoneNumber}"/&gt;
          &lt;DataGridTextColumn x:Name="EmailAdressColumn" Header="Email" Binding="{Binding MailAdress}"/&gt;
          &lt;DataGridTextColumn x:Name="EmployeedDate" Header="Employeed Date" Binding="{Binding EmployedDate}"/&gt;
          &lt;DataGridTextColumn x:Name="BirthdayDate" Header="Birthday     Date" Binding="{Binding BirthDate}"/&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>