Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FrameworkElement.OnVisualParentChanged Method

Invoked when the parent of this element in the visual tree is changed. Overrides OnVisualParentChanged.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
protected internal override void OnVisualParentChanged(
	DependencyObject oldParent
)

Parameters

oldParent
Type: System.Windows.DependencyObject

The old parent element. May be null to indicate that the element did not have a visual parent previously.

The visual tree is potentially different from the logical tree because it omits elements that do not render visually, such as collections, and expands some elements on the basis of their theme and style compositing. For more information, see Trees in WPF.

Notes to Inheritors

The default implementation of this virtual method queries for the new parent, raises various initialization events, and sets internal flags about initialization state of the FrameworkElement as appropriate. Finally, it calls the successive base implementations as declared by UIElement, which in turn calls its base in Visual. Always call the base implementation to preserve this behavior, otherwise the element tree behavior for this element when declared as a child of another element may not be as expected.

A few existing Windows Presentation Foundation (WPF) classes override this method, for example: Window.OnVisualParentChanged, ListBoxItem.OnVisualParentChanged. The most common scenario is to enforce that the new parent must be a particular type. This might involve throwing an exception if the new parent failed some manner of type test. A specialized version of this scenario exists in implementations for list items and menu items, which do not make any sense outside a parent visual that owns an appropriate collection to store them in. Note that these cases do not necessarily raise exceptions, because there might be designer scenarios that rely on reparenting elements that are momentarily without their "regular" parents.

This method is also overridden in certain elements that are typically the root element, such as Window. Another case is elements that are the apparent root element in markup but which autogenerate a greater infrastructure in a compiled logical tree (such as Page). The Window and Page implementations deliberately seal the method.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.