Edward_jie

for you, my Hall of Frame

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
        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 on 2012-01-06 17:16  Edward_诺  阅读(1123)  评论(0编辑  收藏  举报