I customed my TreeViewItem to be a StackPanel
with image
and textblock
inside; I'd like to get a reference to the TextBlock
inside. For the codes below node
is of type TreeviewItem
and I am surechildrenCound =3
which could be StackPanel image textblock
! But it can not find any TextBlock
inside. I never see any console output and object _itemToMove
returns 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+";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");