第一个问题:
没有,你必须自己遍历:
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
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;
}
}
}
}
然后你可以找到page上所有的DataGrid:
foreach (DataGrid dg in FindVisualChildren<DataGrid>(Page))
{
// do something with tb here
}
第二个问题:
开个新帖子,然后我会在新帖子里面跟你讨论。一个帖子尽量问一个问题。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]()