【问题标题】:ListView moving left and right while scrollingListView 在滚动时左右移动
【发布时间】:2015-04-22 15:09:31
【问题描述】:

我有以下列表视图:

<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 => 项目不再被拉伸,这是必要的

  • 将 Horizo​​ntalAlignment = left 添加到 ListView => 再次,项目不再被拉伸......

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 很遗憾,我已经尝试过了,但并没有解决问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多