0
votes

In my wpf project I'm using a datatemplate (which consists of a textblock) as an itemtemplate to my listbox. The itemsource is a List of which there are 6 items. How can I loop through the 6 textblock's that are created at runtime?

Thanks

1
Why do you need to access the controls? Wouldn't you be able to modify them as required using binding against the data source?ZombieSheep
What are you trying to accomplish by looping over those textblocks?Nuffin

1 Answers

1
votes

Do not do it.

Bind everything you need to change to your items and then just change the bound properties, messing with template controls is never a good idea, especially with virtualizing items controls where they may not even exist for all items.

(What you should not use: ItemsControl.ItemContainerGenerator.ContainerFromItem)