Forum Xamarin.Forms

How to edit a ListView's CachingStrategy dynamically in C# code?

dai15002dai15002 Member ✭✭✭

I need help editing CachingStrategy value of a listview. Since it is only readable, I can not change the value directly. I have tried creating custom renderer but no success. How can I edit the CachingStrategy dynamically?

Posts

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    I would say the best idea is to explain why in the world you think you need to do that.

    Secondly, the only way I know of to do it would be to replace the listview with a new one with a different strategy.

    I can't really think of something this would solve, but there it is.

  • dai15002dai15002 Member ✭✭✭

    The searchable listview I use must have CachingStrategy set to RecycleElement in order for images in each row in the list not get lost for Android. However CachingStrategy set to RecycleElement also limites the bindeable data in each row, so one of the rows data is lost on Android when that row is not visible but swiping up or down out of the list. Basically when the row is scrolled back into the list, a bound label's text is lost. This does not happen for iOS.

    When using CachingStrategy = RetainElement then the binding data is not lost, but the images are lost then. So I need to switch between these two CachingStrategy for my list so when the user is loading the list, I have to show the images (by having CachingStrategy = RecycleElement) but when the users do a search I decided to remove the images on the searchresult and set CachingStrategy to RetainElement so the bound label data is not lost.

  • JohnHardmanJohnHardman GBUniversity admin

    @dai15002 - I'd suggest concentrating on solving the specific issues that you are encountering, rather than trying to work around them by attempting to dynamically change the CachingStrategy. I know that you previously posted about an issue that you were hitting when using Label Text in a ListView. You might want to provide more information in that thread so see if people can help you with that, then raise a new thread about the Image problem (assuming that this isn't one that would be resolved by using FFImageLoading). Alternatively, you might want to consider using CollectionView (which seems to be the future) rather than ListView.

  • dai15002dai15002 Member ✭✭✭

    Thanks. This problem is now solved.

  • JohnHardmanJohnHardman GBUniversity admin

    @dai15002 said:
    Thanks. This problem is now solved.

    Can you share the solution, in case it helps anybody else in future.

  • dai15002dai15002 Member ✭✭✭

    I updated the Xamarin.Forms library to the latest one, which solved the issue with bound label texts disappearing.

Sign In or Register to comment.