Listview used with ObservableCollection doesn't load last item properly when deleting from same page

Hi ,

I am trying to display a list of students in listview. I have used ObservableCollection as ItemSource for my listview and when I try to add to the Collection it displayes in UI successfully. Problem arises when I try to remove item from collection I have attached images below. collection length decreses by 1 which is correct but that element is not displayed at all. (if I have n elements in my collection before deleting then also same behaviour is found in that only last element is not displayed properly and all first n-1 elements are displayed as expected)

I am trying to remove element from collection from my view page only.(calling method of viewmodel to make changes in my collection).


  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @GauravKatdare Does pull to refresh resolve it? Also have you implemented the ViewModel with INotifyCollectionChanged? Check if this doc is of use.

  • GauravKatdareGauravKatdare USMember ✭✭

    Hi @ShantimohanElchuri ,
    I have used pull to refersh and in Refreshing event I have again set listView.Itemsource but it gives same result.
    I am not sure why I need to implement INotifyCollectionChanged to my ViewModel, as ObservableCollection already implements that and because of it in UI, elements are changed. I suspect that it is issue of ViewCell. But I can't tell for sure because nothing is showing in Debug console.

  • GauravKatdareGauravKatdare USMember ✭✭
    edited February 13

    Hi All,

    I have solved this issue on Android but same solution is not working in iOS.

    Previously I was using Object of ObservableCollection in my ViewModel and using method to return same instance to listView.Itemsource like below,

    In ViewModel:
    private static ObservableCollection<Student> listofStds = new ObservableCollection<Student>();

    public static ObservableCollection<Student> GetStudents()
    {return listofStds;}

    In View:
    listView.ItemsSource = StudentsViewModel.GetStudents();

    Now I have chnged above code with

    In ViewModel:
    class StudentsViewModel : INotifyPropertyChanged

    private static List<Student> listofStds { get; set; }
    public ObservableCollection<Student> listofStd
    return new ObservableCollection<Student>(listofStds);
    //listofStds = value;

    In View:

    StudentsViewModel viewModel = new StudentsViewModel();

    BindingContext = viewModel;
    listView.SetBinding(ListView.ItemsSourceProperty, "listofStd");

    In iOS, when I run same code below given messages are displayed in Debug Window.

    2019-02-13 16:52:14.323411+0530 NewStudentApp.iOS[90746:419211] SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=90746
    2019-02-13 16:52:14.323666+0530 NewStudentApp.iOS[90746:419211] SecTaskCopyDebugDescription: NewStudentApp.iO[90746]/0#-1 LF=0


Sign In or Register to comment.