locked
Xamarin Forms CollectionView throwing NSInternalInconsistencyException RRS feed

  • Question

  • User389233 posted

    I have a Xamarin forms project which consists of a ColectionView whose ItemSource is backed by a bindable property of type ObservableCollection in the ViewModel. Adding new items to the ObservableCollection is throwing NSInternalInconsistencyException, that too only on actual device whereas in the simulator it's working fine. Also if I create a new local parameter to hold the ItemSources values until all items are added to it and assigning this to the ItemSource bound property also works.

    ObservableCollection _exploreDataList = new ObservableCollection(); public ObservableCollection ExploreDataList { get { return _exploreDataList; } set { _exploreDataList = value; OnPropertyChanged(nameof(ExploreDataList)); } }

    ExploreDataList.Add() will trow NSInternalInconsistencyException. Creating a local variable and adding all values to it and assigning it back to ExploreDataList is working fine. In native ios projects, we used to handle such changes in source through batch updates. But in forms do we need to do that, especially when the CollectionView is backed by the observable collection. Also having a Stacklayout with BindabLayout.itemsource as the ExploreDataList works even when we add new items into the ObservableCollection.

    ie the below code works

    <StackLayout Spacing="{DynamicResource Spacing10}"
                                         Padding="{DynamicResource ExploreMainStkPadding}"
                                         BindableLayout.ItemsSource="{Binding ExploreDataList}"
                                         BindableLayout.ItemTemplateSelector="{DynamicResource ExploreSelector}">
                            </StackLayout>
    

    whereas the below CollectionView code fails

    <CollectionView VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" ItemsSource="{Binding ExploreDataList}" ItemTemplate="{DynamicResource ExploreSelector}"/>

    Friday, November 22, 2019 12:30 PM

All replies

  • User369978 posted

    It works fine if you bind list directly on CollectionView.ItemsSource , please check official sample code .

    Would you mind sharing us a basic, mini project which could reproduce the issue?

    Monday, November 25, 2019 12:25 PM
  • User389233 posted

    @ColeX if I bind it to a list then the collection view appears empty. Post Xamarin-4.2 or 4.3 updates I have observed that 'Add'ing to a list doesn't reflect

    Tuesday, November 26, 2019 6:08 AM
  • User369978 posted

    Could you provide a basic, mini project which could reproduce the issue?

    Just Zip and Attach it in the comment .

    Tuesday, November 26, 2019 9:22 AM