Initial data load into collectionview

-- -- 957 Reputation points
2023-08-28T03:05:38.8433333+00:00

Hi

I have a collection view as below;

           <dxcv:DXCollectionView
               x:Name="JobsListView"
               IsEnabled="True"
               IsPullToRefreshEnabled="True"
               ItemTemplate="{StaticResource JobCardTemplate}"
               ItemsSource="{Binding JobsList}"
               PullToRefreshCommand="{Binding LoadItemsCommand}"
               TapCommand="{Binding ItemTapped}" />

What is the best way to to do initial data load into the collection view? At present I am calling OnLoadItemsCommand() method inthe constructor of the view model as below. This fills the ObservableCollection JobsList that the collectionview is bound to, however it does not give me an activity indicator on the collection view. I am doing the data upload asynchronously in the OnLoadItemsCommand() method.

        public JobsViewModel()
        {
            LoadItemsCommand = new Command<object>(OnLoadItemsCommand);

            ItemTapped = new Command<Jobs>(OnItemSelected);

            JobsList = new ObservableCollection<Jobs>();

            OnLoadItemsCommand();
        }

How can I do the data load ideally so that it also shows the activity indicator?

Any help would be appreciated. Thanks.

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

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,106 Reputation points Microsoft External Staff
    2023-08-29T03:05:51.7233333+00:00

    Hello,

    I checked the PullToRefreshCommand feature of the third-party plugin you're using, which only triggers the update event when you pull down the CollectionView.

    For initializing data in a CollectionView, it is recommended that you initialize it in the ViewModel constructor.

    Please refer to the official sample CollectionViewDemos for more details.

    Best Regards,

    Alec Liu.


    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.