方法一:
利用Grid组件中的Children属性来获得本Grid中包含的第一层的元素
方法二:
public static " href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Collections.Generic.List%3c%3e">List<T> GetAllChildren<T>(FrameworkElement currElement) where T: class
{
if (currElement == null)
{
return null;
}
" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Collections.Generic.List%3c%3e">List<T> list = new .List ();" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Collections.Generic.List%3c%3e">List <T>();
int childrenCount = VisualTreeHelper.GetChildrenCount(currElement);
for (int i = 0; i < childrenCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(currElement, i);
if (child is T)
{
list..Add(T);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Collections.Generic.List%3c%3e/Add(%3c!0%3e)">Add(child as T);
}
if (child is FrameworkElement)
{
list..AddRange(IEnumerable );" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Collections.Generic.List%3c%3e/AddRange(System.Collections.Generic.IEnumerable%3c%3c!0%3e%3e)">AddRange ( DynamicFontPOC.MainPage.GetAllChildren (FrameworkElement currElement);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://DynamicFontPOC:1.0.0.0/DynamicFontPOC.MainPage/GetAllChildren%3c%3e(System.Windows.FrameworkElement):System.Collections.Generic.List%3c%3c!!0%3e%3e">GetAllChildren <T>(child as FrameworkElement));
}
}
return list;
}