【发布时间】:2013-07-30 18:52:02
【问题描述】:
每次将新项目添加到ItemsSource 时,我都在努力使ListView 自动向下滚动到底部。根据this post,我所要做的就是使用以下内容:
private void ScrollToBottom()
{
var scrollViewer = MyListView.GetFirstDescendantOfType<ScrollViewer>();
scrollViewer.ScrollToVerticalOffset(scrollViewer.ScrollableHeight);
}
使用WinRT XAML Toolkit。但是每次从 ListView 的项目集合中添加或删除元素时,我都会调用此方法。但是没有自动滚动。
在 XAML 中,还有 ListView :
<ScrollViewer>
<ListView x:Name="LinesListView"
ItemsSource="{Binding Lines}"
ItemTemplate="{StaticResource LineItemTemplate}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel>
<StackPanel.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</StackPanel.ChildrenTransitions>
</StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</ScrollViewer>
另一方面,在我上面提供的同一链接上还有另一个解决方案,但即使我尝试在 XAML 中指定它,它也不会显示列表视图项动画。
我在这里错过了什么?
非常感谢您的任何建议,谢谢。
【问题讨论】:
-
你知道listview最新的item是什么吗?
-
是的,它们都很好,绑定工作正常,它只是......不向下滚动,这就是为什么我不知道以及如何解决它......
-
我认为您可能会在项目完全添加和创建之前滚动。您也许可以创建一个覆盖 OnItemsChanged 的自定义 ListView 以确保它在项目进入后滚动。
标签: c# listview windows-8 windows-runtime autoscroll