Visual.OnVisualParentChanged(DependencyObject) Method

Definition

Called when the parent of the visual object is changed.

C#
protected internal virtual void OnVisualParentChanged(System.Windows.DependencyObject oldParent);

Parameters

oldParent
DependencyObject

A value of type DependencyObject that represents the previous parent of the Visual object. If the Visual object did not have a previous parent, the value of the parameter is null.

Examples

The following example defines an overridden implementation of OnVisualParentChanged.

C#
public class MyVisual : UIElement
{
    // Class member definitions
    // ...

    protected override void OnVisualParentChanged(DependencyObject oldParent)
    {
        // Perform actions based on OnVisualParentChanged event.
        // ...

        // Call base class to perform standard event handling.
        base.OnVisualParentChanged(oldParent);
    }
}

Remarks

A class that derives from Visual can choose to override this method.

There is no "VisualParentChanged" event provided that reports this change to instances. Therefore, you must override this method to handle notification scenarios and provide an instance version of the notification if that is part of your scenario.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also