Share via


FrameworkElement.Parent Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the parent object of this FrameworkElement in the object tree.

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

Syntax

'Declaration
Public ReadOnly Property Parent As DependencyObject
public DependencyObject Parent { get; }

Property Value

Type: System.Windows.DependencyObject
The parent object of this object in the object tree.

Remarks

Parent may be nulla null reference (Nothing in Visual Basic) in cases where an object was instantiated, but is not attached to an object that eventually connects to the Silverlight RootVisual, or the application object.

In the core Silverlight classes, the parent of a FrameworkElement can also be expected to be a FrameworkElement as long as it is not returned as nulla null reference (Nothing in Visual Basic). But custom classes might introduce a content model where this assumption is not true.

Note that the parent of an object can potentially change depending on your application's functionality, and keeping the value of this property as an instance will not reflect that change. You typically should get the parent object value immediately before you need it for other operations, and should not rely on the value past this point.

Note that this property is read-only. Changing the parent of an object can be accomplished, but is only done through manipulation of collections. For example, you can change a parent relationship by using dedicated add or remove methods, or through setting container properties of objects such as Children on a Panel.

Silverlight Tree Concepts and WPF

If you are familiar with WPF, you might know that WPF maintains several related tree concepts for programmatic access to the run-time object graph, such as a visual tree and a logical tree. In WPF, the Parent property reports the parent in the logical tree. Silverlight does not provide an API (equivalent of LogicalTreeHelper in WPF) that could provide concrete access to a logical tree, and therefore the Silverlight documentation does not devote a topic to explaining the logical tree concept to Silverlight programmers. However, the FrameworkElement.Parent value reports on the logical tree result, to provide API equivalence to WPF. Generally, you can conceive of the logical tree as being a tree that describes containment through a nested series of objects and property values. If a given object has one or more contained children held in some type of "Content" or "Children" property, the FrameworkElement.Parent describes the inverse of that relationship.

The value reported by the FrameworkElement.Parent property in Silverlight is generally the same value that would be reported by using VisualTreeHelper API, because the two tree concepts are frequently synchronized as far as how parent-child relationships are reported. However, there may be cases where FrameworkElement.Parent reports a parent that VisualTreeHelper does not.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.