How to make main window wait until a newly opened window closes in C# WPF?

Arjun Ajith

I am new to WPF as well as C#, please bear with me.

I have a main window which opens up a new window. Now this new window is a prompt whether or not to overwrite a file, and the main window accesses a public variable in the new window to check for the prompt's result.

But I can't get the main window processing to wait until the new window closes.

 Window1 Win = new Window1();
 Win.Show();

 if (Win.pr_res == 1)
 {
      abc.Text = "File to be overwritten";
      File.Delete(_destination);
      Start();
 }
 else
 {
      abc.Text = "Operation Aborted";
 }

I tried adding a while loop checking another public boolean in the main window, but that just hangs the entire program.

 while(!_closecheck);

Any suggestions are welcome.

Rohit Vats

Use ShowDialog instead of Show -

Win.ShowDialog();

From MSDN -

Opens a window and returns only when the newly opened window is closed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

the newly opened pop up window closes itself... how can I stop this?

From Dev

WPF+PRISM How to make the popup window owner as main window

From Dev

How do I make a newly opened file the active window on GNOME 3?

From Dev

How do I make a newly opened file the active window on GNOME 3?

From Dev

WPF disable main window while second window is open until it closed

From Dev

In WPF how do I make textbox in main window update?

From Dev

How close window that opened in a thread in wpf?

From Dev

How to close newly opened window in Jmeter webdriver Sampler.?

From Dev

How to focus a datatemplated TextBox in the first element of an ItemsControl in a Window, when the Window is opened? (C#, WPF)

From Dev

How do I know when WPF application has opened the main window?

From Dev

How to make a WPF Window responsive

From Dev

Get element of a newly opened & loaded window - Javascript

From Dev

Remove a node from the newly opened window jquery

From Dev

Newly opened window is not getting preferences from parent window in selenium webdriver

From Dev

How to make a `Tool` window always on top of 2 or more Main window?

From Dev

Main Window closes after execvp() call

From Dev

PyQt5 dialog closes main window

From Dev

How to get the newly opened apps WPF

From Dev

Can I make a script wait for a key press when it has opened itself in a new terminal window?

From Dev

ctrl+c closes terminal window completely - why / how?

From Dev

WPF main window does not return

From Dev

Passing variables to a newly opened window - nwj (node-webkit)

From Dev

Desktop file icon hijacks every newly opened terminal window

From Dev

Trigger an element click on newly opened browser window using Jquery

From Dev

Selenide test not able to load correct element on a newly opened tab/window

From Dev

How to set your main window invisble to show a image as main window in WPF

From Dev

How to make state of window idle until button is pressed in python tkinter?

From Dev

How do I make the frame keep repainting until window close?

From Dev

How to wait main thread until async task is completed in C#

Related Related

  1. 1

    the newly opened pop up window closes itself... how can I stop this?

  2. 2

    WPF+PRISM How to make the popup window owner as main window

  3. 3

    How do I make a newly opened file the active window on GNOME 3?

  4. 4

    How do I make a newly opened file the active window on GNOME 3?

  5. 5

    WPF disable main window while second window is open until it closed

  6. 6

    In WPF how do I make textbox in main window update?

  7. 7

    How close window that opened in a thread in wpf?

  8. 8

    How to close newly opened window in Jmeter webdriver Sampler.?

  9. 9

    How to focus a datatemplated TextBox in the first element of an ItemsControl in a Window, when the Window is opened? (C#, WPF)

  10. 10

    How do I know when WPF application has opened the main window?

  11. 11

    How to make a WPF Window responsive

  12. 12

    Get element of a newly opened & loaded window - Javascript

  13. 13

    Remove a node from the newly opened window jquery

  14. 14

    Newly opened window is not getting preferences from parent window in selenium webdriver

  15. 15

    How to make a `Tool` window always on top of 2 or more Main window?

  16. 16

    Main Window closes after execvp() call

  17. 17

    PyQt5 dialog closes main window

  18. 18

    How to get the newly opened apps WPF

  19. 19

    Can I make a script wait for a key press when it has opened itself in a new terminal window?

  20. 20

    ctrl+c closes terminal window completely - why / how?

  21. 21

    WPF main window does not return

  22. 22

    Passing variables to a newly opened window - nwj (node-webkit)

  23. 23

    Desktop file icon hijacks every newly opened terminal window

  24. 24

    Trigger an element click on newly opened browser window using Jquery

  25. 25

    Selenide test not able to load correct element on a newly opened tab/window

  26. 26

    How to set your main window invisble to show a image as main window in WPF

  27. 27

    How to make state of window idle until button is pressed in python tkinter?

  28. 28

    How do I make the frame keep repainting until window close?

  29. 29

    How to wait main thread until async task is completed in C#

HotTag

Archive