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 屬性隱含地鎖定 Mode 屬性值為 FindAncestor

XAML 文字使用方式

如需 XAML 資訊,請參閱 RelativeSource MarkupExtension

適用於

另請參閱