public static void SearchVisualTree(DependencyObject targetElement,
int width,
string Node)
{
var count = VisualTreeHelper.GetChildrenCount(targetElement);
if (count ==
0)
{
return;
}
for (
int i =
0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(targetElement, i);
if (child
is TextBlock)
{
TextBlock targetItem = (TextBlock)child;
if (targetItem.Name == Node)
targetItem.Width = width;
}
else {
SearchVisualTree(child, width,Node);
}
}
}
用法:DBHelper.VisualTree(listboxname,300,"textBox1");