Visual.OnVisualParentChanged(DependencyObject) Visual.OnVisualParentChanged(DependencyObject) Visual.OnVisualParentChanged(DependencyObject) Visual.OnVisualParentChanged(DependencyObject) Method


当可视对象的父级更改时调用。Called when the parent of the visual object is changed.

protected public:
 virtual void OnVisualParentChanged(System::Windows::DependencyObject ^ oldParent);
protected internal virtual void OnVisualParentChanged (System.Windows.DependencyObject oldParent);
abstract member OnVisualParentChanged : System.Windows.DependencyObject -> unit
override this.OnVisualParentChanged : System.Windows.DependencyObject -> unit
Protected Friend Overridable Sub OnVisualParentChanged (oldParent As DependencyObject)


DependencyObject DependencyObject DependencyObject DependencyObject

一个表示 DependencyObject 对象的上一个父级的 Visual 类型值。A value of type DependencyObject that represents the previous parent of the Visual object. 如果 Visual 对象没有上一个父级,则参数的值为 nullIf the Visual object did not have a previous parent, the value of the parameter is null.


下面的示例定义的OnVisualParentChanged重写实现。The following example defines an overridden implementation of OnVisualParentChanged.

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.
Public Class MyVisual
    Inherits UIElement
    ' Class member definitions
    ' ...

    Protected Overrides Sub OnVisualParentChanged(ByVal oldParent As DependencyObject)
        ' Perform actions based on OnVisualParentChanged event.
        ' ...

        ' Call base class to perform standard event handling.
    End Sub
End Class


从派生的Visual类可以选择重写此方法。A class that derives from Visual can choose to override this method.

未提供可向实例报告此更改的 "VisualParentChanged" 事件。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.