c#代码修改xaml中listbox的datatemplate中的控件

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.SearchVisualTree(listboxname,300,"textBox1");

posted @ 2012-01-16 23:28  zhh  阅读(178)  评论(0编辑  收藏  举报