SiberianGuy
SiberianGuy

Reputation: 25312

Does it make sense to set Owner for Dialog window

If I set Owner to a Window and show it in non-dialog mode I get two things: 1. Child window is always on the top of parent window (while there is still access to parent window) 2. If I close parent window, the child window will be closed too

In case of dialog window both points do not make sense: 1. Child window is on the top of parent window independently on Owner property 2. You have no chance to close parent window

So am I right there is no sense setting Owner property to Dialog windows or may be there are some arguments for that?

Upvotes: 1

Views: 442

Answers (2)

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

Besides to what H.B. said,

It’s important to set the owner of a Window before showing it, because otherwise weird bugs can occur where a focused or modal window is hidden behind other windows. To prevent such bugs, you set the Owner property to the current Window.

Mark Seemann, Dependency Injection in .NET

Upvotes: 2

brunnerh
brunnerh

Reputation: 184554

As the documentation points out there are reasons:

When you open a child window by calling ShowDialog, you should also set the Owner property of the child window. If you don't, then your users won't be able to restore both child window and parent window by pressing the task bar button. Instead, pressing the task bar button will yield a list of windows, including both child and parent window, for them to select; only the selected window is restored.

You should also set the Owner property on a window that that is opened by calling ShowDialog to ensure correct behavior with UI Automation.

Upvotes: 2

Related Questions