title: Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed
body: <p>Refering to my last question <a href="https://stackoverflow.com/questions/18568850/binding-in-combobox-xaml-wpf">https://stackoverflow.com/questions/18568850/binding-in-combobox-xaml-wpf</a>, I add a property FirstName in ClientBookKeepingViewModel. But now I got an error <img src="https://i.stack.imgur.com/zRNCk.png" alt="enter image description here">. </p>
  
  <p>When I debug using breakpoint, the error comes from View.ShowDialog() <img src="https://i.stack.imgur.com/bgQki.png" alt="enter image description here"></p>
  
  <p>My code is as follows:</p>
  
  <pre><code>  public int InsertClientBooking(int clientID, ClientBookKeepingViewModel k)
      {
          var client = new ClientBooking();
  
          using (var context = new ProActiveDBEntities())
          {
              client.ClientBookID = k.ClientBookKeepingID;
              client.ClientID = k.ClientID;
              client.EmployeeID = k.EmployeeID;
              client.WorkType = k.WorkType;
              client.DateRecorded = (DateTime)k.DateRecorded;
              client.BookingFormCompleted = k.BookingFormCompleted;
              client.TimeBudgetCompleted = k.TimeBudgetCompleted;
              client.ProposedCompletionDate = (DateTime)k.ProposedCompletionDate;
              client.IsCompleted = k.IsCompleted;
              client.FirstName = k.FirstName;
  
              context.Clients.First(i =&gt; i.ClientID == clientID).ClientBookings.Add(client);
  
              context.SaveChanges();
  
              return clientID;
          }
      }
  
  
  
        private void btnAddBooking_Click(object sender, RoutedEventArgs e)
      {
          ClientBookingView view = new ClientBookingView();
          ClientBookKeepingViewModel book = new ClientBookKeepingViewModel();
  
          book.Client = (ClientViewModel)this.DataContext;
  
          book.Mode = Mode.Add;
          view.DataContext = book;
          view.ShowDialog();
      }
  </code></pre>
  
  <p><strong>ClientBookingView.Xmal</strong></p>
  
  <pre><code>&lt;ComboBox Grid.Column="1" Grid.Row="1" Name="cbEmployeeName" 
   ItemsSource="{Binding Source={StaticResource Employee}}" 
   DisplayMemberPath="FirstName" 
   SelectedValue="{Binding Path=FirstName, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
   SelectedValuePath="FirstName"
  
  &lt;CheckBox Grid.Column="1" Grid.Row="5" Name="dpBookingCompleted" Content="Yes" 
   IsChecked="{Binding BookingFormCompleted, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}"/&gt;
  /&gt;
  &lt;StackPanel Grid.Row="9"  Orientation="Horizontal" Grid.ColumnSpan="3" Margin="0,5,20,0" Grid.Column="1"&gt;
          &lt;Button x:Name="btnUpdate" Width="80" Margin="10" Height="25"
                      Command="{Binding ShowUpdateCommand}" 
                      Click="btnUpdate_Click"&gt;
  
              &lt;Button.Style&gt;
                  &lt;Style TargetType="{x:Type Button}" BasedOn="{StaticResource MetroButton}"&gt;
                      &lt;Setter Property="IsEnabled" Value="False"/&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding Mode}"&gt;
                              &lt;DataTrigger.Value&gt;
                                  &lt;enum:Mode&gt;Add&lt;/enum:Mode&gt;
                              &lt;/DataTrigger.Value&gt;
                              &lt;Setter Property="Content" Value="Add"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;DataTrigger Binding="{Binding Mode}"&gt;
                              &lt;DataTrigger.Value&gt;
                                  &lt;enum:Mode&gt;Edit&lt;/enum:Mode&gt;
                              &lt;/DataTrigger.Value&gt;
                              &lt;Setter Property="Content" Value="Save"/&gt;
                          &lt;/DataTrigger&gt;
                          &lt;MultiDataTrigger&gt;
                              &lt;MultiDataTrigger.Conditions&gt;
                                  &lt;Condition Binding="{Binding ElementName=cbEmployeeName, Path=(Validation.HasError)}" Value="false"/&gt;
                                  &lt;Condition Binding="{Binding ElementName=cbWorkType, Path=(Validation.HasError)}" Value="false"/&gt;
                                  &lt;Condition Binding="{Binding ElementName=dpDateRecord, Path=(Validation.HasError)}" Value="false"/&gt;
                                  &lt;Condition Binding="{Binding ElementName=dpProposedCompletionDate, Path=(Validation.HasError)}" Value="false"/&gt;
                              &lt;/MultiDataTrigger.Conditions&gt;
                              &lt;Setter Property="IsEnabled" Value="True"/&gt;
                          &lt;/MultiDataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/Button.Style&gt;
          &lt;/Button&gt;
  
          &lt;Button x:Name="btnCancel" Content="Cancel" Margin="10" Width="80" Height="25"
                      Command="{Binding CancelCommand}"
                      Click="btnCancel_Click" /&gt;
      &lt;/StackPanel&gt;
  </code></pre>
  
  <p><strong>ClientBookListView</strong></p>
  
  <pre><code> &lt;ListView Name="lsvClientOwnerTypeList" Height="150" Width="700"
                    ScrollViewer.VerticalScrollBarVisibility="Visible" 
                    ScrollViewer.HorizontalScrollBarVisibility="Visible" 
                    HorizontalAlignment="Center"
                    VerticalAlignment="Top"
                    IsSynchronizedWithCurrentItem="True"
                    ItemsSource="{Binding ClientBookList}"
                    SelectedItem="{Binding SelectedClientBook}"&gt;
  
              &lt;ListView.View&gt;
                  &lt;GridView&gt;
                      &lt;GridViewColumn CellTemplate="{StaticResource RowButtons}"/&gt;
                      &lt;GridViewColumn Header="Completed" DisplayMemberBinding="{Binding IsCompleted}"  /&gt;
                      &lt;GridViewColumn Header="Employee Name" DisplayMemberBinding="{Binding FirstName}" /&gt;
                      &lt;GridViewColumn Header="Work Type" DisplayMemberBinding="{Binding WorkType}"  /&gt;
                      &lt;GridViewColumn Header="Date Recorded" DisplayMemberBinding="{Binding DateRecorded, StringFormat={}\{0:dd/MM/yyyy\}}"  /&gt;
                      &lt;GridViewColumn Header="Booking Form Completed" DisplayMemberBinding="{Binding BookingFormCompleted}"  /&gt;
                      &lt;GridViewColumn Header="Time Budget Completed" DisplayMemberBinding="{Binding TimeBudgetCompleted}"  /&gt;
                      &lt;GridViewColumn Header="Proposed Completion Date" DisplayMemberBinding="{Binding ProposedCompletionDate, StringFormat={}\{0:dd/MM/yyyy\}}"  /&gt;
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
          &lt;/ListView&gt;
  </code></pre>