Expandable ListView without Implementing IsVisible in the Model?

Hi,

I want to create an expandable ListView. There are many online tutorials for this, however they all involve adding a bool "IsVisible" or "IsExpanded" property to the item Model to keep track of which view cell(s) should be expanded and which shouldn't.

However, in my case, the model is a list of dynamic objects that are platform specific. Essentially, I can't/don't want to mess with the model.
How can I make an expandable listview based on an ItemTapped event (Or ItemSelected state?) without touching the model?

I've Included a link for an example of the expanded version when you CAN add to the item model: https://blogs.naxam.net/expandable-viewcell-with-datatrigger-59f5315fd90e

Thanks!

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited November 2018

    How can I make an expandable listview based on an ItemTapped event (Or ItemSelected state?) without touching the model?

    I think it is impossible.

    If you click the item to collapse this cell , how does the cell know if it's expanded or collapsed without the IsVisible property ?

  • DR_BartDR_Bart Member ✭✭

    I there a way to keep track of whether it is expanded or collapsed from the ViewModel?

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭

    Hi
    if you don't have a lot of items, you may use https://github.com/AndreiMisiukevich/ExpandableView with RepeaterView or StackLayout for example (it work's badly with listView)

  • GaetanFGaetanF USMember ✭✭✭

    Well, if you don't want to mess with the model, you could wrap it in a view model that manages the expansion through bindings and exposes the model's data. View models are the right place to do so, even behind cells of ListView.

Sign In or Register to comment.