Preventing listview from scrolling back to the top when removing item
Please use ObservableCollection
type to replace List
type for ItemsSource
. And avoid re-set the ItemsSource
after removing the item. Please check the following demo code.
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
private ObservableCollection _items;
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
_items = new ObservableCollection();
for (int i = 0; i < 100; i++)
{
_items.Add($"Cuttent index is {i}");
}
MyListView.ItemsSource = _items;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
_items.RemoveAt(60);
}