I have a class that populates a ListView by passing a list of objects. The class uses reflection to see the properties of each object in order to generate the ListView. How
You could use the ItemContainerGenerator, e.g:
var lvitem = listView.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem;
var lvitem = listView.ItemContainerGenerator.ContainerFromIndex(0) as ListViewItem;
However by default the ListView
is virtualizing, this means ListViewItems
are created on the fly as needed (only if the item is actually visible in the list), so the above methods will not return containers for items which are currently not visible.
This being the case it usually is preferable to define a binding on the Background
property via a Setter
in the ItemContainerStyle.