For example:
there is a listbox:
<ListBox Margin="24,107,12,28" Name="lb">
<TextBlock Text="Text" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
<TextBlock Text="Text2" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
<TextBlock Text="Text3" TextWrapping="Wrap" FontSize="22" Visibility="Collapsed" />
</ListBox>
How can I change TextBlocks’s visibility properties programmatically?
The
ListBoxgenerates a container of typeListBoxItemfor each item. You can access it as follows:If you want access to the
TextBlockyou will need to navigate the visual tree of theListBoxItem. For example, using Linq to VisualTree: