我遇到了一些奇怪的行为,似乎无法解决。当我迭代我的ListBox.ItemsSource属性中的项目时,我无法获取容器?我期望看到返回一个ListBoxItem,但只得到null。
有什么想法吗?
这是我使用的代码:
this.lstResults.ItemsSource.ForEach(t =>
{
ListBoxItem lbi = this.lstResults.ItemContainerGenerator.ContainerFromItem(t) as ListBoxItem;
if (lbi != null)
{
this.AddToolTip(lbi);
}
});
ItemsSource目前设置为字典,并包含许多键值对。