MVVM Binding throws exception if Itemsource collection is created in a loop

Hi,
this is really strange behavour, I cant even explain what is going on here. i have mvvm binding works fine on andorid 6 emulator but It fails with exception below on Android 8.0 emulator. Please test it with Android 8 and 6 to see the difference, you should load sfkanban, click back button and try to load sfkanban page again, repeat this a few times. you will see that sometimes works, sometimes doesnt.
I have simply xaml as.
ItemTapped="SfKanban_ItemTapped" DragEnd="Kanban_DragEnd" Columns="{Binding KanbanColumns}" ItemsSource="{Binding KanbanModels}">
public ObservableCollection KanbanModels { get; set; }
public KanbanColumnCollection KanbanColumns { get; set; }
  • Syncfusion.SfKanban.XForms.Droid
    KanbanEventDependencyService.SetItemsSource(Syncfusion.SfKanban.XForms.SfKanban formKanban, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  • 1
    Syncfusion.SfKanban.XForms
    SfKanban.Data_CollectionChanged(System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  • 2
    System.Collections.ObjectModel
    ObservableCollection`1[T].OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  • 3
    System.Collections.ObjectModel
    ObservableCollection`1[T].OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index)
  • 4
    System.Collections.ObjectModel
    ObservableCollection`1[T].InsertItem(System.Int32 index, T item)
  • 5
    System.Collections.ObjectModel
    Collection`1[T].Add(T item)


2 Replies

EM Emil May 2, 2018 10:30 AM UTC

I have figured out in which case this is happening, If I add kanbanmodels as below one by one with for loop, it throw this exception irregularly. 

public ObservableCollection KanbanModels { get; set; }

for (int i = 1; i <= SomeCount; i++)
 KanbanModels.Add(new  KanbanModel());

but If I create another list and add models into the list and after that create a new ObservableCollection from that list, it will work fine. somehing like below

   var KanbanModelList = new List<KanbanModel>();

          for (int i = 1; i <= SomeCount; i++)
                            programKanbanModelList.Add(new  KanbanModel());
  
 KanbanModels = new ObservableCollection<KanbanModel>(KanbanModelList );

It looks like that adding item fires some Changed event as the stacktrace indicates and it is crashing for some reason. 


SG Sridharan Gajendran Syncfusion Team May 7, 2018 11:26 AM UTC

Hi Emil, 

Thanks for contacting Syncfusion Support. 

Please share us the more details about where you are adding the data whether in the constructor of the ViewModel or in any other events.  

Regards, 
Sridharan 


Loader.
Up arrow icon