Invoked when the parent of this element in the visual tree is changed. Overrides OnVisualParentChanged.
Assembly: PresentationFramework (in PresentationFramework.dll)
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.
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.