qshinoの日記

Powershell関係と徒然なこと

wpf window owner property

owner property

Windowの親子関係と振る舞い。親子関係は、子のowner propertyに親を設定する事で決まる。親子関係を設定した場合、どちらかのウインドウの振る舞いが他に影響する。未設定の場合は影響しない。また、ユーザープログラムが子ウインドウのownerプロパティを設定する。親のOwnedWindows propertyのアクセスはgetのみであり、外部から設定できない。子のowner propertyが反映される模様。

親子関係

親子関係は自動では設定されず、ユーザープログラムで設定する。

未設定時の振る舞い

どちらかのウインドウのclose/minimize/maximizeによる親子ウインドウへの影響なし。タスクバーではそれぞれ別ウインドウとして表示される。

設定時の振る舞い

和訳 1. 親を最小化するとすべての子も最小化される。 2. 子を最小化しても親には影響なし。 3. 親を最大化すると、親子全てが元に戻る。 4. 親は子を覆わない。 5. ShowDialogで開かれなかった子はモードレス。子を開いても親は入力を受け付ける。 6. 親を閉じると全ての子が閉じられる 7. show()で開いた子に対しては、親を閉じてもClosing eventが送られない。

英文

    1. 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. 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.

重要

子をShowDialog()で表示した場合も、親子関係を設定する事。自動では設定されない。

設定方法 C#
// Create a window and make this window its owner
Window ownedWindow = new Window();
ownedWindow.Owner = this;
ownedWindow.Show();