ListView: how to prevent visual glitches during scrolling

ListView: how to prevent visual glitches during scrolling

Prelude

My friend Samuel Blanchard just wrote an article (in french) including some tips about ListView this morning, do not hesitate to read it also: http://blog.naviso.fr/wordpress/?p=2078

To complete this article, I will share one of the control I use to improve the ListView experience.

How to prevent shifts in ListView

If you’re familiar with the ListView control, perhaps you know there is a little problem when you scroll items, a small shift of the control to the right (or left) can happen and is really boring.

So here is a tip to prevent this behavior: If the ItemsPanel’s width is manually set, the glitch disappears!

Here is a very small class to manage it automatically even if the control is resized (switch from portrait to landcape for example):

namespace Huyn.Controls
{
public class PerfectScrollListView : ListView
{

public PerfectScrollListView()
{
this.SizeChanged += PerfectScrollListView_SizeChanged;
}

private void PerfectScrollListView_SizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e)
{

if(ItemsPanelRoot!=null)
ItemsPanelRoot.Width = e.NewSize.Width;
}
}

Comments are closed.