ObservableCollection Binding Exception - MVVM ItemSource

I get an exception in xamarin.forms android and ios projects in my listview but not in uwp. Itemsource returns an exception when I use binding with the viewmodel. When i don't use binding in my xaml the exception disappears.

System.ArgumentNullException has been thrown
Value cannot be null.
Parameter name: element

private ObservableCollection<T> pages = new ObservableCollection<T>();

        public ObservableCollection<T> Pages 
        {
            get { return pages; }
            set
            {
                pages = value;
                OnPropertyChanged("Pages");
            }
        }

and in the constructor I use

            public ViewModel()
                {

                        Pages = someitems;
                }

In xaml I bind ItemSource to Pages

ItemsSource="{Binding Pages}

When I remove Binding from Xaml I don't get the exception. What do I miss?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited August 2017

    The example project built here walks the reader through building up an MVVM solution binding the UI to an ObservableCollection and hits on some of the common issues. I would suggest you step away from your solution, take 20 minutes to go through the site and build the example from start to end. It shouldn't long and may reveal what you're missing.

  • GerasimosAlexiouGerasimosAlexiou GRMember ✭✭
    edited August 2017

    the problem seems to be in the setter pages = value; but I cannot find it

Sign In or Register to comment.