RelativeSource.AncestorLevel 属性

定义

FindAncestor 模式获取或设置要查找的上级级别。 使用 1 指示最靠近绑定目标元素的项。

public:
 property int AncestorLevel { int get(); void set(int value); };
public int AncestorLevel { get; set; }
member this.AncestorLevel : int with get, set
Public Property AncestorLevel As Integer

属性值

上级级别。 使用 1 指示最靠近绑定目标元素的项。

示例

以下内容返回从绑定的目标元素开始的向上路径上遇到的第二个 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

适用于

另请参阅