在上面的XAML代码中,我使用以下代码获取ItemsControl x:Name="PointsList"的子元素,并且获取到的数量为0。你能帮我解决这个问题吗?
int count = VisualTreeHelper.GetChildrenCount(pointsList);
if (count > 0)
{
for (int i = 0; i < count; i++)
{
UIElement child = VisualTreeHelper.GetChild(pointsList, i) as UIElement;
if (child.GetType() == typeof(TextBlock))
{
textPoints = child as TextBlock;
break;
}
}
}
pointsList的定义如下。
pointsList = (ItemsControl)GetTemplateChild("PointsList");