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: 1.4.3.6372
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()
        {
            base.OnAppearing();
            listview.ItemsSource = new [] { 1,2,3,4};
        }           
    }

Posts

Sign In or Register to comment.