Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkContentElement.Parent Property

Gets the parent in the logical tree for this element.

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

public DependencyObject Parent { get; }
/** @property */
public DependencyObject get_Parent ()

public function get Parent () : DependencyObject

You cannot use this property in XAML.

Property Value

The ogical 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 Element Tree 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.

// Traverse content in forward direction until the position is immediately after the opening 
// tag of a Run element, or the end of content is encountered.
while (position != null)
{
    // Is the current position just after an opening element tag?
    if (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
    {
        // If so, is the tag a Run?
        if (position.Parent is Run)
            break;
    }

    // Not what we're looking for; on to the next position.
    position = position.GetNextContextPosition(LogicalDirection.Forward);
}

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft