다음을 통해 공유


DependencyObjectExtensions

이 형식은 DependencyObjectExtensions 개체에 대한 DependencyObject 확장 메서드 컬렉션을 제공합니다. 이 클래스는 클래스 사용을 지원하기 위해 여러 API를 노출합니다 VisualTreeHelper . 시각적 트리를 걷는 것이 유용할 수 있는 여러 가지 이유가 있으며 이는 문서에 멘션.

구문

// Include the namespace to access extensions
using Microsoft.Toolkit.Uwp.UI;

// Find a visual descendant control using its name
var control = uiElement.FindDescendant("MyTextBox");

// Find the first visual descendant control of a specified type
control = uiElement.FindDescendant<ListView>();

// Find all visual descendant controls of the specified type.
// We use LINQ here to filter children of a specific type.
using System.Linq;

foreach (var child in uiElement.FindDescendants().OfType<ListViewItem>())
{
    // ...
}

// Find the first visual ascendant control using its name
control = uiElement.FindAscendant("MyScrollViewer");

// Find the first visual ascendant control of a specified type
control = uiElement.FindAscendant<ScrollViewer>();

예제

단위 테스트에서 더 많은 예제를 찾을 수 있습니다.