0

I have following ListView:

<ListView ItemsSource="{Binding ArtistList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Border BorderThickness="0,0,0,0.5" BorderBrush="#22ffffff" Tapped="ArtistTapped">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Ellipse Grid.Column="0" Canvas.ZIndex="0" Fill="#22ffffff" Width="50" Height="50" Margin="0,10"/>
                    <Ellipse Grid.Column="0" Canvas.ZIndex="1" Stretch="UniformToFill" Width="50" Height="50" Margin="0,10">
                        <Ellipse.Fill>
                            <ImageBrush ImageSource="{Binding firstAlbumArt}"/>
                        </Ellipse.Fill>
                    </Ellipse>
                    <StackPanel Grid.Column="1" Margin="20,10,0,10">
                        <TextBlock Text="{Binding name}" Foreground="#ffffffff" FontFamily="Segoe WP" FontSize="18"/>
                        <TextBlock Foreground="#aaffffff" FontFamily="Segoe WP" FontWeight="Light" FontSize="14">
                            <Run Text="{Binding amountofalbums}"/>
                            <Run Text="album(s)"/>
                        </TextBlock>
                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

When I scroll up and down, the ListView moves slightly right and left, which is very irritating. There are two ways to fix this:

  • Removing the ItemContainerStyle => items aren't stretched anymore which is necessary

  • Adding HorizontalAlignment = left to the ListView => again, items aren't stretched anymore...

Is there a way to keep the ListView from jumping left and right while maintaining stretched ListViewItems?

Philippe Maes
  • 510
  • 9
  • 26

2 Answers2

1

It's a bug in the current OS due to virtualisation in the ListView.

The best solution so far that I found is by giving the items in the list an actual width that matches the parent.

It has been discussed on stack overflow already here : https://stackoverflow.com/questions/24361850/listview-in-windows-phone-8-1-wobbles-while-scrolling-though-long-list-xaml/24400075#24400075

Community
  • 1
  • 1
Depechie
  • 6,102
  • 24
  • 46
0

Set ScrollViewer.HorizontalScrollMode="Disabled" in the ListView. It should stop the unwanted scrolling behavior.

<ListView ItemsSource="{Binding ArtistList}" ScrollViewer.HorizontalScrollMode="Disabled">
    <!-- rest of xaml code -->
</ListView>
Abhishek
  • 1,349
  • 8
  • 17