RelativeSource.AncestorType 属性

定义

获取或设置要查找的上级节点的类型。

public:
 property Type ^ AncestorType { Type ^ get(); void set(Type ^ value); };
public Type AncestorType { get; set; }
member this.AncestorType : Type with get, set
Public Property AncestorType As Type

属性值

上级节点的类型。 默认值是 null

例外

示例

以下内容返回从绑定的目标元素开始的向上路径上遇到的第二个 ItemsControl

Binding myBinding = new Binding();
// Returns the second ItemsControl encountered on the upward path
// starting at the target element of the binding
myBinding.RelativeSource = new RelativeSource(
    RelativeSourceMode.FindAncestor, typeof(ItemsControl), 2);
Dim myBinding As New Binding()
' Returns the second ItemsControl encountered on the upward path
' starting at the target element of the binding
myBinding.RelativeSource = New RelativeSource(RelativeSourceMode.FindAncestor, GetType(ItemsControl), 2)

注解

如果未显式设置 属性 Mode ,则设置 AncestorTypeAncestorLevel 属性会将属性值隐式锁定 ModeFindAncestor

XAML 文本用法

有关 XAML 信息,请参阅 RelativeSource MarkupExtension

适用于

另请参阅