答案 0 :(得分:0)
public static IEnumerable<T> FindVisualChildren<T>(System.Windows.DependencyObject depObj) where T : System.Windows.DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
System.Windows.DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
在mi创建活动方法中我做:
foreach (TextBlock tb in RulesDll.ObjectsClass.FindControls.FindVisualChildren<TextBlock>(target))
{
string a = tb.Text;
}