How to bring a new window open in front of Main Wi

2019-09-17 19:53发布

问题:

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();
    

回答1:

Set the Owner for your 2. window like this:

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


回答2:

I got it correct when I gave like this:

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


标签: c# wpf mvvm