Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Off by one error when setting ListView.ItemsSource

I updated from an old version of Xamarin.Forms to the latest version and I am now seeing an issue when setting the ItemsSource property of a ListView in the OnAppearing event of a page, when running on Android. If you try the repro code below, the alert will show "2" when you click on the row for item 1. If you move the line of code setting the ItemsSource into the constructor, then you will get the correct behavior.

Xamarin.Forms version:
Android version: API Level 19

    public class MyPage : ContentPage
        private ListView listview;

        public MyPage()
            listview = new ListView ();            
            listview.ItemTapped += (sender, e) =>
                DisplayAlert("testing", e.Item.ToString(), "ok");                

            this.Content = listview; 

        protected async override void OnAppearing()
            listview.ItemsSource = new [] { 1,2,3,4};


Sign In or Register to comment.