DependencyObjectExtensions
DependencyObjectExtensions
型は、DependencyObject
オブジェクト用の拡張メソッドのコレクションを提供します。 このクラスは、VisualTreeHelper
クラスの使用に役立ついくつかの API を公開します。 ビジュアル ツリーのウォーキングが有用である理由はいくつかあり、それらについてはこちらのドキュメントで言及されています。
構文
// 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>();
例
「単体テスト」では、さらに他の例を確認できます。
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
Windows Community Toolkit