私は、新しい要素を追加するためのリストビューとbuttomの2つの要素がある例を作成しました。あなたは、ボタン、スクロールをよりよく示すために非常に巨大で見ることができるように
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<ListView x:Name="ListView" />
<Button
Grid.Row="1"
Clicked="Button_OnClicked"
Text="Add animal" />
</Grid>
:
は、これは私のXAMLです。私のコードビハインドで
、私はアニメーションで最後に追加された要素にスクロールするListView.ScrollTo
メソッドを使用します。私は、これはあなたを助けることができることを願っています
public partial class MainPage : ContentPage
{
private ObservableCollection<String> animals;
private int _counter = 0;
public MainPage()
{
InitializeComponent();
animals = new ObservableCollection<string>(new List<string>{"dog","cat","fish","elephant","monkey"});
ListView.ItemsSource = animals;
}
private void Button_OnClicked(object sender, EventArgs e)
{
var newElement = "new animal"+_counter;
_counter++;
animals.Add(newElement);
ListView.ScrollTo(newElement, ScrollToPosition.End, true);
}
}
。
ありがとう、私の友人!成功!完璧に働いた!ありがとうございました! –