Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ListView Performance & Caching Strategy

$
0
0

Hello, everybody!

I have a question about ListView performance. Is there any way to display a large list of rows with different templates? I had tried a lot of recipes including DataTemplateSelector, custom ViewCell, etc but list still very slow while scrolling. At last I implemented this idea with ListViewCachingStrategy.RecycleElement and got quite fast list, but all the rows are shuffled. But if I'm using the same template for each row everything works as expected (rows are ordered). So, is there any way to achieve this? Thanks beforehand!

The ViewCell which I have used with ListViewCachingStrategy.RecycleElement:

public class ChatItemViewCell : ViewCell
    {
        private readonly ChatItemQuestionView questionView = null;
        private readonly ChatItemAnswerView answerView = null;
        private ChatItem context = null;

        public ChatItemViewCell()
        {
            questionView = new ChatItemQuestionView();
            answerView = new ChatItemAnswerView();
        }

        protected override void OnBindingContextChanged()
        {
                base.OnBindingContextChanged();
                context = BindingContext as ChatItem;

                if (context != null)
                {
                    if (context.IsBot)
                    {
                        questionView.UpdateContext(context);
                        View = questionView;
                    }
                    else
                    {
                        answerView.UpdateContext(context);
                        View = answerView;
                    }
                }
        }
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>