Performance improvement while loading a collection View

Manickam, Suraj 320 Reputation points
2024-02-23T07:22:20.4166667+00:00

Hi , I have to load a collection that has a huge data , I use async task to fetch the data from service and use loading indicator till then , when I navigate to the response screen , it takes a bit of time to populate the collection view which makes the user to see the main screen without the loading indicator ! How can I make the user see the loading indicator until the page is ready to be loaded?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,720 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,256 Reputation points Microsoft Vendor
    2024-02-26T08:12:30.1166667+00:00

    Hello,

    For your layout, you can set ActivityIndicator's IsVisible="true" and set the Collectionview's IsVisible="false"

    <ActivityIndicator VerticalOptions="Center" HorizontalOptions="Center" x:Name="myActivityIndicator" IsVisible="true" IsRunning="true" />
      <CollectionView x:Name="myCollectionview" >
         ...
      </CollectionView>
    

    Then, you can load the data in the OnAppearing method. I use a Task.Delay to simulate loading data. when Task is finished, We can set myCollectionview.IsVisible = true; and hide the ActivityIndicator by myActivityIndicator.IsVisible = false;

    protected override 
    {
        base.OnAppearing();
    
    
       myCollectionview.IsVisible = false;
     
           MainThread.BeginInvokeOnMainThread(() => {
    
               myCollectionview.IsVisible = true;
                myActivityIndicator.IsVisible = false;
           });
        
        });
    }
    

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.