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
)
You cannot use methods in XAML.

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 than the logical tree, in that it omits elements that have no renderable visual, such as collections, and expands some elements on 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 instance: Window.OnVisualParentChanged, ListBoxItem.OnVisualParentChanged. The most common scenario is to enforce that the new parent be of a particular type. This might involve thrown 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.

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft