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.

FrameworkElement.TemplatedParent Property

Gets a reference to the template parent of this element. This property is not relevant if the element was not created through a template.

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

public DependencyObject TemplatedParent { get; }
You cannot set this property in XAML.

Property Value

Type: System.Windows.DependencyObject
The element whose FrameworkTemplate VisualTree caused this element to be created. This value is frequently null; see Remarks.

TemplatedParent is frequently null for objects that are created in your application markup or code. This is because you create those objects directly, not via a template. Object references obtained by walking the logical tree from the root, or by typical name references, do not come from a template.

Cases where TemplatedParent might not be null include operations such as hit-testing, event handling for certain low-level input events, walking the visual tree with VisualTreeHelper, or working with enumerators, which might return elements that came from templates. Another case is if you specifically call FindName against an existing FrameworkTemplate and are work with the returned object.

Templates are actually shared objects, where the contents of the template are created only once. Therefore, if you obtain an object reference to an element that came from a template, you may find that the apparent logical tree does not reach to the page root. In order to connect such a template reference to the page's logical tree, you should get the TemplatedParent value and continue to navigate that element tree as desired.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0

Community Additions

Show:
© 2014 Microsoft