title: WPF Refresh window on closing of child window
body: <p>I am developing a WPF application using MVVM where I'm trying to show and add a job title (which is basically a string). So, in "index" view I'll show all the list from a SQL Server database, at the top of the list there's an "Add new Job title" which opens a new window with a textbox and button. </p>
  
  <pre><code>// this is my collection that holds the job titles
  public ObservableCollection&lt;JobTitle&gt; JobTitles
  {
     get { return _jobTitles; }
     set
     {
       if (_jobTitles == value) return;
       _jobTitles = value;
       OnPropertyChanged();
     }
  }
  JobTitles = GetJobTitles();
  
  // opens up a new window
  private void AddNewJobTitleCommandHandler()
  {
          var createJobTitleWindow = new CreateJobTitle()
          {
              ShowInTaskbar = false,
              Owner = Application.Current.MainWindow,
              Title = "Add New Job Title"
          };
  
          createJobTitleWindow.ShowDialog();
  }
  </code></pre>
  
  <p>From "Add New Job Title" window I'm using this: </p>
  
  <pre><code>private void AddJobTitleCommandHandler()
  {
          if (JobTitleInput == null) return;
  
          var jt = new JobTitle { Description = JobTitleInput };
          _dbContext.JobTitles.Add(jt);
          _dbContext.SaveChanges();
  
          var windows = Application.Current.Windows;
          // closes the last opened window ?? better way to do
          windows[windows.Count - 1].Close();
          windows[0].Focus();
          JobTitles = GetJobTitles();
  }
  </code></pre>
  
  <p>Although I'm updating the <code>JobTitles</code> after closing the window it's not refreshing the Listbox I'm using to show the <code>JobTitles</code></p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding JobTitles}" Grid.Row="2"&gt;
          &lt;ListBox.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto" Name="Description" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;TextBlock Text="{Binding Description}" /&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListBox.ItemTemplate&gt;
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>How can I update my parent page after closing the child window?</p>
  
  <hr>
  
  <p>UPDATE
  OK I have it working by doing this: </p>
  
  <pre><code>windows[windows.Count - 1].DialogResult = true; // in AddJobTitleCommandHandler
  </code></pre>
  
  <p>And in AddNewJobTitleCommandHandler</p>
  
  <pre><code>if (createJobTitleWindow.ShowDialog() == true)
  {
       // update after create window is closed
       JobTitles = GetJobTitles();
  };
  </code></pre>