How to resolve the issue of not being able to close a new window in WPF?

If you are unable to close a new window opened in a WPF application, you can try the following solution:

  1. The opening in a building that allows light to enter and provides a view of the outside.
  2. Display in the taskbar
  3. correct
<Window ...
        ShowInTaskbar="True">
    ...
</Window>
  1. “I need to close the window.”
  2. Proprietor
  3. Proprietor
NewWindow newWindow = new NewWindow();
newWindow.Owner = Application.Current.MainWindow;
newWindow.Show();
  1. Shut it.
  2. Press the button
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}
  1. Close the current application.
  2. Press
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Shutdown();
}

Following the above steps should resolve the issue of being unable to close a new window opened in a WPF application.

bannerAds