【发布时间】:2018-06-06 21:18:07
【问题描述】:
我试图弄清楚如何使用列表视图可用的 ScrollTo 方法。我相信我的最后两个论点是正确的,但我不太确定我的第一个论点是否正确。
这是带有我的列表视图的 xaml...
<ListView
x:Name="MyList"
Grid.Row="0"
Grid.RowSpan="4"
Grid.Column="0"
Grid.ColumnSpan="8"
ItemsSource="{Binding History}"
ItemTapped="OnItemTapped"
RowHeight="60">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="8">
<Label
Text="{Binding MessageTitle}"
FontAttributes="Bold" />
<Label
Text="{Binding MessageContents}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是我尝试使用 .ScrollTo 的视图背后的部分代码
private void ScrollToBottomClicked(object sender, EventArgs e)
{
List.ScrollTo(MyList.ItemsSource, ScrollToPosition.End, true);
}
这里是 ItemSource,它是我的视图模型中的一个可观察集合
public ObservableCollection<HistoryMessage> History
{
get
{
return History;
}
set
{
History = value;
}
}
当单击 ScrollToBottom 按钮时,我希望列表视图显示跳转到最近添加的项目。任何帮助将不胜感激!
【问题讨论】:
标签: c# xaml xamarin xamarin.forms