简体   繁体   中英

How to bring a new window open in front of Main Window in WPF after switching to any other application in MVVM architecture?

How can I resolve the following problem?

  1. Run a WPF app, MainWindow is opened in front
  2. New window is shown behind after opening any other application Main window is also disabled then have to press the ALT+Tab to take the new window and close it.

     NewWindow newWindow = new NewWindow (); newWindow.ShowDialog();

Set the Owner for your second window like this:

NewWindow newWindow = new NewWindow();
newWindow.Owner = this;
newWindow.ShowDialog();

I got it correct when I gave like this:

  NewWindow newWindow = new NewWindow ();
  newWindow.Owner= Application.Current.MainWindow;
  newWindow.ShowDialog();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM