title: How to give the user a choice of closing a wpf window from its window_loaded event
body: <p>I do some checking when a WPF window opens by some code in the Window_loaded sub of the WPF Window.</p>
  
  <p>In certain conditions, I need to give the a choice to a user via a messagebox.show and close the window.  </p>
  
  <pre><code>        If MessageBox.Show("Question the user?",
                           "Ask", MessageBoxButton.OKCancel, MessageBoxImage.Question) = MessageBoxResult.OK Then
            'do some further code
          Else
            Me.Close()
          End If
  </code></pre>
  
  <p>Currently when I do this, when the Messagebox shows up, the wpf window is shown as a black window.  </p>
  
  <p><strong>Question1: How can I get the messageBox without showing the WPF window as a black box behind it</strong></p>
  
  <p>Here's the full code in the load_window event.  </p>
  
  <pre><code>'Initialise window when Load event flagged
  'The window expects to called after a Status variable is set to the newly   created window object
  'status=1 then it attempts to load the current activity
  'status=2 then it checks the user has a current activity, offers to a)stop and save it and then open a new activity Or b) close.
  'status=other, shouldn't happen, theres an error close the application
  
  Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
  log.logInDB(clsLoggedInUser.login, "CurrentActivityWindow", "Info", "Form Loading. Status" &amp; status)
  
  Select Case Me.status
    Case 1 'Current Activity
      'Ask the Activity to load details for the users current Activity
      Debug.Print("Window loaded - current Activity")
      myActivity.GetCurrentActivityForUser(clsLoggedInUser.login)
    Case 2 'New Activity
      Debug.Print("Window loaded - new Activity")
      myActivity.GetCurrentActivityForUser(clsLoggedInUser.login)
      If myActivity.ID &gt; 0 Then
        log.logInDB(clsLoggedInUser.login, "CurrentActivityWindow", "Info", "User already has an activity. Stop it and save or close")
        If myActivity.activityStart.HasValue Then
          If MessageBox.Show("Already have an active activity, Stop it and create a new one?",
                           "New Activity", MessageBoxButton.OKCancel, MessageBoxImage.Question) = MessageBoxResult.OK Then
            'stop and create new one
            myActivity.StopActivity()
            myActivity.save()
            log.logInDB(clsLoggedInUser.login, "CurrentActivityWindow", "Info", "Setting up New Activity")
            newActivity()
          Else
            Debug.Print("Closing Form - Opened as new activity but user has a current activity and didnt want to stop it.")
            Me.Close()
            Exit Sub
          End If
        Else
          If MessageBox.Show("Already have an active activity without a start time, will load that up for you.",
               "New Activity", MessageBoxButton.OK, MessageBoxImage.Information) = MessageBoxResult.OK Then
          End If
        End If
      Else
        log.logInDB(clsLoggedInUser.login, "CurrentActivityWindow", "Info", "No current Activity, calling newActivity")
        newActivity()
      End If
    Case Else
      Debug.Print("Error: CurrentActivity Status not set")
      log.logInDB(clsLoggedInUser.login, "CurrentActivityWindow", "Info", "Tried opening window without Status being set.")
      Application.Current.Shutdown()
  End Select
  
  Debug.Print("CurrentActivityWindow - Filling Project List")
  buildProjectList()
  DataContext = projectsList
  
  Debug.Print("CurrentActivityWindow - Updating GUI")
  updateGUI()
  </code></pre>
  
  <p>End Sub</p>