WPF之VisualTreeHelper
Posted 流星小子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF之VisualTreeHelper相关的知识,希望对你有一定的参考价值。
/// <summary>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="parent"></param>
/// <returns></returns>
public IEnumerable<T> FindChildren<T>(DependencyObject parent) where T : class
{
var count = VisualTreeHelper.GetChildrenCount(parent);
if (count > 0)
{
for (var i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
var t = child as T;
if (t != null)
yield return t;
var children = FindChildren<T>(child);
foreach (var item in children)
yield return item;
}
}
}
以上是关于WPF之VisualTreeHelper的主要内容,如果未能解决你的问题,请参考以下文章