次の方法で共有


Variable height items? Stick with Stackpanel

So here I was, trying to make a ListBox in Windows Phone (Silverlight) scroll properly and for some reason, the thing just wouldn't scroll ok, sometimes items would stick in the middle, sometimes forcing the layout to update worked sometimes it didn't, almost like a race condition of sorts. Well, turns out that the ListBox control uses a virtualized stackpanel that assumes that all your items in the list have the same height (see this post https://blogs.msdn.com/b/slmperf/archive/2010/10/06/silverlight-for-windows-phone-7-listbox-scroll-performance.aspx).  The problem in my app? the items are not of the same size and in fact they can grow dynamically as their content changes.

Solution? Use a stack panel instead with a scroll viewer. Since my app doesn't require loading hundresds of items (50 at most) the memory consumption is not a concern.  Scrolling to the end works flawlesly and manual scrolling is smooth as silk.

Happy coding