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

2019-09-17 19:52发布

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

标签: c# wpf mvvm
2条回答
Explosion°爆炸
2楼-- · 2019-09-17 19:58

Set the Owner for your 2. window like this:

NewWindow newWindow = new NewWindow ();
newWindow.Owner=this;
newWindow.ShowDialog();
查看更多
别忘想泡老子
3楼-- · 2019-09-17 20:05

I got it correct when I gave like this:

  NewWindow newWindow = new NewWindow ();
  newWindow.Owner= Application.Current.MainWindow;
  newWindow.ShowDialog();
查看更多
登录 后发表回答