Share via

Performance improvement while loading a collection View

Manickam, Suraj 385 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?

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    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.

    Was this answer helpful?


Your answer

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