ListView在滚动时左右移动

时间:2015-04-22 15:09:32

标签: xaml listview windows-8 windows-phone-8.1 windows-8.1

我有以下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>

当我向上和向下滚动时,ListView会略微左右移动,这非常令人恼火。有两种方法可以解决这个问题:

  • 删除ItemContainerStyle =&GT;物品不再被拉伸,这是必要的

  • 将Horizo​​ntalAlignment = left添加到ListView =&GT;再次,物品不再被拉伸......

有没有办法让ListView在保持拉伸的ListViewItems时保持左右跳跃?

2 个答案:

答案 0 :(得分:1)

由于ListView中的虚拟化,这是当前操作系统中的一个错误。

到目前为止,我找到的最佳解决方案是给列表中的项目提供与父项匹配的实际宽度。

已经讨论了堆栈溢出问题:https://stackoverflow.com/questions/24361850/listview-in-windows-phone-8-1-wobbles-while-scrolling-though-long-list-xaml/24400075#24400075

答案 1 :(得分:0)

ScrollViewer.HorizontalScrollMode="Disabled"中设置ListView。它应该停止不必要的滚动行为。

<ListView ItemsSource="{Binding ArtistList}" ScrollViewer.HorizontalScrollMode="Disabled">
    <!-- rest of xaml code -->
</ListView>