How to list UIElements elements in ListView elements?

I am trying to access UIElementin VisualTreefor ListView, but it is ItemsCollectionempty, even if ListView IsLoaded, IsInitializedand has elements in DataContext.

How do I get access UIElementsto ListView? Is there any event that I can attach to wait for items to be available?

thank

+3
source share
1 answer

You can subscribe to ItemsContainerGenerator.StatusChanged, and in the handler, check whether the status has ContainersGenerated:

myListView.ItemContainerGenerator.StatusChanged += OnListViewItemsStatusChanged;

-

private void OnListViewItemsStatusChanged(object sender, EventArgs e) {
    if (myListView.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) {
        // access items
    }
}
+2
source

Source: https://habr.com/ru/post/1795241/


All Articles