Export (0) Print
Expand All
0 out of 12 rated this helpful - Rate this topic

Window.Owner Property

Gets or sets the Window that owns this Window.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public Window Owner { get; set; }
/** @property */
public Window get_Owner ()

/** @property */
public void set_Owner (Window value)

public function get Owner () : Window

public function set Owner (value : Window)

<object>
  <object.Owner>
    <Window .../>
  </object.Owner>
</object>

Property Value

A Window object that represents the owner of this Window.
Exception typeCondition

ArgumentException

A window tries to own itself

-or-

Two windows try to own each other.

InvalidOperationException

The Owner property is set on a visible window shown using ShowDialog

-or-

The Owner property is set with a window that has not been previously shown.

When a child window is opened by a parent window by calling ShowDialog, an implicit relationship is established between both parent and child window. This relationship enforces certain behaviors, including with respect to minimizing, maximizing, restoring.

When a child window is created by a parent window by calling Show, however, the child window does not have a relationship with the parent window. This means that:

  • The child window does not have a reference to the parent window.

  • The behavior of the child window is not dependent on the behavior of the parent window; either window can cover the other, or be minimized, maximized, and restored independently of the other.

To allow you to create a relationship between a child window and a parent window, Window supports the notion of ownership. Ownership is established when the Owner property of a window (the owned window) is set with a reference to another window (the owner window).

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

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.

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

NoteNote:

You cannot set or get this property when a window is hosted in a browser.

The following example shows how to establish the owner/owned relationship.

// Create a window and make this window its owner
Window ownedWindow = new Window();
ownedWindow.Owner = this;
ownedWindow.Show();

  • UIPermission  for permission to use all windows and user input events without restriction. Associated enumeration: AllWindows

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.