Please consider the following XAML code:
<ListBox Name="listBox1" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Border Name="border1">
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
and we assign a simple array to it:
listBox1.DataContext = new[] { "A", "B", "C" };
Now the question is how we can access the generated objects for Border (or TextBlock instances)?
- It is not possible by "border1". It does not exist.
listBox1.ItemContainerGenerator.ContainerFromIndex(0)
returns a ListBoxItem but content of that ListBoxItem is of type String.FindName("border1")
returns null
Update: What I expect to find are 3 instances of Border (and 3 TextBlocks, one in each Border).