共用方式為


GetParent

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

Gets the parent object of the calling object.

retval = object.GetParent()

Return Value

Type: object

A reference to the parent object if successful; otherwise, returns null.

Managed Equivalent

FrameworkElement.Parent

Remarks

The only objects that can contain UIElement children are Canvas and InkPresenter. The UIElement types that can be child objects of Canvas and InkPresenter are listed in the "Applies To" section of this topic.

Calling the GetParent method on Canvas or on any other object that is at the XAML root will return null. To retrieve the hosting plug-in instance, always use the GetHost method.

Path can have child elements, but these are geometries instead of UIElement objects. Therefore, you cannot call GetParent on a Path's child elements. As a workaround, you should always name the Path so that it can be accessed without having to walk the tree.

Applies To

Border (Silverlight 2)

Canvas

Ellipse

Glyphs

Image

InkPresenter

Line

MediaElement

PasswordBox (Silverlight 2)

Path

Polygon

Polyline

Popup (Silverlight 2)

Rectangle

StackPanel (Silverlight 2)

TextBlock

TextBox (Silverlight 2)

See Also

Reference