title: How do I fire a custom event from a child window back to parent window?
body: <p>I am looking to close the application when I click a cancel button in a login page, but I don't want to do it in such a way that Window 2 closes itself, but by sending some notification to Main Window, and Main Window closes the application. Here's the code that I have so far:</p>
  
  <p>(in loginPage)</p>
  
  <pre><code>Public Event CloseApp As EventHandler
  
  Private Sub CancelButton_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CancelButton.Click
  
      DialogResult = False
      RaiseEvent CloseApp(Me, New EventArgs)
  End Sub
  </code></pre>
  
  <p>(In Main Window)</p>
  
  <pre><code>Public loginPage As New LoginPage
  
  Public Sub New()
      InitializeComponent()
      AddHandler loginPage.CloseApp, AddressOf Me.ShutDownJobChangeWindow
  End Sub
  
  Private Sub ShutDownJobChangeWindow(ByVal sender As Object, ByVal e As EventArgs)
      Application.Current.Shutdown()
  End Sub
  </code></pre>
  
  <p>This does not work. I am new to handling events so if anyone could help explain what's wrong with this I would be very grateful to you!</p>
  
  <p>P/S: I am not too sure about C# too would appreciate code in VB.NET.</p>