Home > Mobile >  Xamarin forms expandableListView/Syncfusion/CollectionView issue to limite items
Xamarin forms expandableListView/Syncfusion/CollectionView issue to limite items

Time:02-22

I'm trying to use any expandable list in order to limit the size of the list, for example, the list returns 30 items I want to display 3. However, I'm having the option that when they expand the list the rest of 27 items will display . and when it collapses ,

we still see 3 items as the original item size setup. Any code snippet a t this point is very helpful .Thanks enter image description here

I tried to limit the size in code like this

foreach (var cusName in CustomerNames)
            {
                if (counter == 13)
                    counter = 1;
                var contact = new Contact(cusName);
                contact.CallTime = CallTime[i];
                contact.PhoneImage = ImageSource.FromResource("ExpandableListView.Images.PhoneImage.png", assembly);
                contact.ContactImage = ImageSource.FromResource("ExpandableListView.Images.Image"   counter   ".png", assembly);
                contact.AddContact = ImageSource.FromResource("ExpandableListView.Images.AddContact.png", assembly);
                contact.NewContact = ImageSource.FromResource("ExpandableListView.Images.NewContact.png", assembly);
                contact.SendMessage = ImageSource.FromResource("ExpandableListView.Images.SendMessage.png", assembly);
                contact.BlockSpan = ImageSource.FromResource("ExpandableListView.Images.BlockSpan.png", assembly);
                contact.CallDetails = ImageSource.FromResource("ExpandableListView.Images.CallDetails.png", assembly);
                i  ;
                if (ContactsInfo.Count > 2)
                {
                    ContactsInfo.RemoveAt(2);

                }
                ContactsInfo.Add(contact);

and in fact , it removes the rest , but now I dont know how to display the rest when the click the expand option

enter image description here

CodePudding user response:

You can achieve it in many ways, I will explain in a simple way.

In the Contact class add another property bool IsExpanded = false. And make it true for the first 3 items and show the list items based on this property. And make "false" for rest of the items by default. As soon as you clicked on expanded button make all of them to "true" for IsExpanded property. Automatically, all items will be visible. Do more customization as per your requirement. Hope this will work and suits for requirement mark it as Answer. Happy Coding :)

CodePudding user response:

There's more ways to archive this.. Anyway I've created a little sample repo. If can help you :)

Link: https://github.com/AlessandroLanzoni/ExpandibleList_Sample

Another link that can you help => https://www.c-sharpcorner.com/article/xamarin-forms-expandable-listview-with-a-sub-listview-mvvm-pattern/

  • Related