Greetings. The question is concerning a PCL Xamarin.Forms project.
I have a ListView which is bound to an ObservableCollection. I would like for the list to auto-scroll to the latest added item in the ObservableCollection.
I tried to attach myself to the ObservableCollection's CollectionChanged event and then use "lvMessages.ScrollTo(ViewModel.Messages.Last(), ScrollToPosition.End, true);" , but that didn't work as intended, it actually produced a crash.
Crash report :
Message :
Value cannot be null. Parameter name: key
StackTrace :
at System.Collections.Generic.Dictionary2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at Xamarin.Forms.Platform.WinPhone.ListViewRenderer.GetReusable(Dictionary2 reusables, DataTemplate template, Object dataContext)
at Xamarin.Forms.Platform.WinPhone.ListViewRenderer.OnScrollToRequested(Object sender, ScrollToRequestedEventArgs e)
at Xamarin.Forms.Platform.WinPhone.ListViewRenderer.<>c__DisplayClass9.<OnScrollToRequested>b__2(Object o, ViewportChangedEventArgs args)
at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at System.Windows.Controls.Primitives.ViewportControl.OnViewportChanged(Object sender, EventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Any ideas how to achieve the auto-scrolling behavior, or what to modify so that it no longer crashes ?
Thanks !