简体   繁体   English

WPF设置所有者窗口不起作用

[英]Wpf set owner window not working

I have a main Window that I want it to be the owner of all other windows 我有一个主窗口,希望它成为所有其他窗口的所有者

from the class of the main window this was the code 在主窗口的类中,这是代码

private voide btn_Click()
 {
      SomeWindow w = new SomeWindow()
      w.Owner = this;
      w.Show();
  }

also tried 也尝试过

w.Owner = Application.Current.MainWindow

but it never works 但它永远都行不通

According to your comment, it seems that you want something like this: 根据您的评论,您似乎想要这样的东西:

 w.ShowInTaskbar = false;

or you might want to do: 或者您可能想做:

w.ShowDialog();

Note what Owner-Child relationships do : 注意所有者-子关系的作用

Once this relationship is established, the following behaviors are exhibited: 一旦建立了这种关系,就会表现出以下行为:

  • If an owner window is minimized, all its owned windows are minimized as well. 如果将所有者窗口最小化,则其所有拥有的窗口也将最小化。

  • If an owned window is minimized, its owner is not minimized. 如果将拥有的窗口最小化,则其所有者也不会最小化。

  • If an owner window is maximized, both the owner window and its owned windows are restored. 如果将所有者窗口最大化,则将同时还原所有者窗口及其拥有的窗口。

  • An owner window can never cover an owned window. 所有者窗口永远不能覆盖拥有的窗口。

  • Owned windows that were not opened using ShowDialog are not modal. 未使用ShowDialog打开的自有窗口不是模态的。 The user can still interact with the owner window. 用户仍然可以与所有者窗口进行交互。

  • If you close an owner window, its owned windows are also closed. 如果关闭所有者窗口,则其拥有的窗口也会关闭。

  • If an owned window was opened by its owner window using Show, and the owner window is closed, the owned window's Closing event is not raised. 如果所有者窗口使用“显示”打开了所有者窗口,并且所有者窗口已关闭,则不会引发所有者窗口的“关闭”事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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