Parent Property

FrameworkContentElement.Parent Property

Gets the parent in the logical tree for this element.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

member Parent : DependencyObject

Property Value

Type: System.Windows.DependencyObject
The logical parent for this element.

Note that the logical parent of an element can potentially change depending on your application functionality, and keeping the value of this property will not reflect that change. You typically should get the value immediately before you need it.

See Trees in WPF for more information about traversing logical trees, and the scenarios where taking this approach towards element discovery is appropriate.

The property system will potentially recalculate all property values of an element when it is reparented, because some properties inherit values through the logical tree. The DataContext that applies for bindings can also change when elements are reparented.

Changing an element's parent is typically only done through manipulation of collections, by using dedicated add or remove methods, or through setting content properties of elements.

The most typical scenario for using the Parent property is to obtain a reference and then get various FrameworkContentElement property values from the parent. For templates, the Parent of the template eventually will be a null reference (Nothing in Visual Basic). To get past this point and extend into the logical tree where the template is actually applied, use TemplatedParent.

The following example checks to see whether the Parent of a TextPointer is of a particular type.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2016 Microsoft