【发布时间】:2011-01-24 23:32:32
【问题描述】:
在上面的 XAML 代码中,我使用下面的代码获取子项(ItemsCotnrol 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");
【问题讨论】:
-
使用树来处理 ItemsControl 的内容不是一个好习惯。那么你想用 TextBox 做什么呢?
-
我想为 TextBlock 捕捉鼠标事件。有办法吗?请告诉我。
-
只需在 ItemsControl 级别挂钩鼠标事件,然后让事件冒泡。
标签: wpf wpf-controls