For example: there is a listbox:
The ListBox
generates a container of type ListBoxItem
for each item. You can access it as follows:
ListBoxItem lbi = lb.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem
lbi.Visibility = Visibility.Collapsed;
If you want access to the TextBlock
you will need to navigate the visual tree of the ListBoxItem
. For example, using Linq to VisualTree:
TextBlock txt = lbi.Descendants<TextBlock>().Single() as TextBlock;