Reputation: 75
I'm trying to access UIElement
s in the VisualTree
of a ListView
but the ItemsCollection
is empty even though the ListView
IsLoaded
, IsInitialized
and has items in DataContext
.
How can I access UIElements
in a ListView
? Is there an event I can attach myself on to wait for the items to be accessible?
Thanks
Upvotes: 3
Views: 641
Reputation: 20756
You can subscribe to ItemsContainerGenerator.StatusChanged
and in the handler check whether the status is ContainersGenerated
:
myListView.ItemContainerGenerator.StatusChanged += OnListViewItemsStatusChanged;
-
private void OnListViewItemsStatusChanged(object sender, EventArgs e) {
if (myListView.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) {
// access items
}
}
Upvotes: 2