我将我的 TreeViewItem 定制为StackPanel
withimage
和textblock
inside;我想得到TextBlock
内部的参考。因为下面的代码node
是类型的TreeviewItem
,我相信childrenCound =3
它可能是StackPanel image textblock
!但它在里面找不到任何TextBlock
东西。我从来没有看到任何控制台输出和object _itemToMove
返回null
TreeViewItem node = UIHelper.FindVisualParent<TreeViewItem>(e.OriginalSource as FrameworkElement);
var child = VisualTreeHelper.GetChild(node, 0);
int childrenCount = VisualTreeHelper.GetChildrenCount(child);
for (int i = 0; i < childrenCount; i++)
{
TextBlock vc = VisualTreeHelper.GetChild(child, i) as TextBlock;
if (vc != null)
{
Console.WriteLine("ggggggggggggggggggggggggggggggggggggggggggggggg");
_itemToMove = vc.Text as object;
}
}
Console.WriteLine(childrenCount+";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");