打个比方,如果你想找一个wpf页面里所有TextBox,可以使用VisualTreeHelper的方法去找
private void EnumVisual(Visual myVisual)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
{
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
if (childVisual != null)
{
if (childVisual is TextBox) (childVisual as TextBox).Text = "Winner";
EnumVisual(childVisual);
}
}
}
传参数的时候传this即可