Skip to main content
.NET Framework Class Library
FrameworkElementParent Property

Gets the logical parent element of this element.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax
Public ReadOnly Property Parent As [%$TOPIC/ms600897_en-us_VS_110_1_0_0_0_0%]
public [%$TOPIC/ms600897_en-us_VS_110_1_0_1_0_0%] Parent { get; }
public:
property [%$TOPIC/ms600897_en-us_VS_110_1_0_2_0_0%]^ Parent {
	[%$TOPIC/ms600897_en-us_VS_110_1_0_2_0_1%]^ get ();
}
member Parent : [%$TOPIC/ms600897_en-us_VS_110_1_0_3_0_0%] with get

Property Value

Type: System.WindowsDependencyObject
This element's logical parent.
Remarks

Parent may be in cases where an element was instantiated, but is not attached to any logical tree that eventually connects to the page level root element, or the application object.

Note that the logical parent of an element can potentially change depending on your application's 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 logical tree traversal, and the scenarios where using Parent as a technique of parent element discovery is appropriate.

The property engine 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 FrameworkElement property values from the parent. For templates, the Parent of the template eventually will be . To get past this point and extend into the logical tree where the template is actually applied, use TemplatedParent.

Note that this property does not report visual tree parents in cases where these vary from the logical tree parents. Visual tree parents are not typically important for general application cases but may be the desired parent elements for certain visual level cases. See VisualTreeHelper.

Examples

The following example shows code that checks for an element's parent, and then uses property values from the parent to set properties on the child element to match. In this case these are properties that affect the rendering size.

		Private Sub OnUIReady(ByVal sender As Object, ByVal e As System.EventArgs)
			LinePane.Width = (CType(LinePane.Parent, StackPanel)).ActualWidth
			LinePane.Height = (CType(LinePane.Parent, StackPanel)).ActualHeight
			AddHandler DesignerPane.MouseLeave, AddressOf DesignerPane_MouseLeave
			AddHandler SizeChanged, AddressOf Window1_SizeChanged
		End Sub
private void OnUIReady(object sender, System.EventArgs e)
{
    LinePane.Width = ((StackPanel)LinePane.Parent).ActualWidth;
    LinePane.Height = ((StackPanel)LinePane.Parent).ActualHeight;
    DesignerPane.MouseLeave += new System.Windows.Input.MouseEventHandler(DesignerPane_MouseLeave);
    this.SizeChanged += new SizeChangedEventHandler(Window1_SizeChanged);
}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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