This is a migrated thread and some comments may be shown as answers.

RadList and bound ObservableCollection

6 Answers 288 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
N Mackay
Top achievements
Rank 1
N Mackay asked on 20 Jan 2016, 02:21 PM

Hi,

Why can't we add an item to a bound ObservableCollection? it throws a dictionary exception

The only way to work around it is this kind of fudge:

var copy = new ObservableCollection<OrderItem>(Orders) {newOrder};
Orders = new ObservableCollection<OrderItem>(copy);

It worked fine before with a Xamarin Listview, when I refactored an existing app for Telerik RadList then this issue arose. Our WPF guys were saying they have the same issue with the WPF RadGrid.

Is this intended behavior or a bug? 

Thanks,

Norman.

6 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 22 Jan 2016, 11:48 AM
Hello Norman,

Thank you for contacting us.

I have tested several scenarios where a list view is bound to an observable collection and I could not reproduce the issue. I tried with collection of value type items and collection of equal items as I suspected this could be a problem, with and without item template. I have attached the test project. Could you please take a look and modify it to reproduce the issue.

I look forward to your reply.

Regards,
Rosy Topchiyska
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
N Mackay
Top achievements
Rank 1
answered on 25 Jan 2016, 03:43 PM

Hi Rosy, 

I promise this didn't work in the last version I was using but having upgraded to the latest stable release I can delete from and clear the collection with no exceptions.

I did update your sample to use the same type of json dto's use and couldn't reproduce the issue either.

Thanks for your assistance,

Norman.

 

 

0
N Mackay
Top achievements
Rank 1
answered on 28 Jan 2016, 04:40 PM

Hi Rosy,

The issue seems to be caused by a customrenderer in Android. 

If you are using the renderer below the calling Collection.Clear() will throw an exception.

 

public class CustomRadListRenderer : ListViewRenderer
{
    protected override SwipeExecuteBehavior CreateSwipeExecuteBehavior(ListViewDataSourceAdapter adapter)
    {
        var behavior = base.CreateSwipeExecuteBehavior(adapter);
        behavior.AutoDissolve = false;
        behavior.SwipeLimitStart = 0;
        return behavior;
    }
}

The code is to stop the user swiping and revealing from the right. If I stop using the CustomRenderer then clear/add etc work as expected.

I'm guessing this approach has been deprecated for an newer approach but I'm not sure. Also could you advice how to stop this behavior in iOS?

The error is shown below:

 

System.Collections.Generic.KeyNotFoundExceptionThe given key was not present in the dictionary.
Raw
System.ThrowHelper.ThrowKeyNotFoundException()
System.Collections.Generic.Dictionary<TKey, TValue>.get_Item(TKey key)
at Telerik.XamarinForms.Common.XamarinToNativeControlExtensions.UpdateCollection[T,K] (Telerik.XamarinForms.Common.T nativeElement, Telerik.XamarinForms.Common.K xfЕlement, System.String propertyName, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) <0x897cd380 + 0x0005b> in <filename unknown>:0
Telerik.XamarinForms.DataControlsRenderer.Android.ListViewRenderer.ItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Telerik.XamarinForms.DataControls.RadListView.RaiseItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
System.Collections.ObjectModel.ObservableCollection<T>.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
System.Collections.ObjectModel.ObservableCollection<T>.OnCollectionReset()
System.Collections.ObjectModel.ObservableCollection<T>.ClearItems()
System.Collections.ObjectModel.Collection<T>.Clear()

I'd rather ensure the Listview's as expected rather than coding in workarounds for data binding so it would be good if I could get a solution, essentially I only want the user to swipe right on a listitem and not allow swipe left.

Thanks again.,

Norman.

0
N Mackay
Top achievements
Rank 1
answered on 28 Jan 2016, 04:49 PM

Hi,

The Renderer also affects Collection.Delete()

 

System.Collections.Generic.KeyNotFoundExceptionThe given key was not present in the dictionary.
Raw
System.ThrowHelper.ThrowKeyNotFoundException()throwhelper.cs:70
System.Collections.Generic.Dictionary<TKey, TValue>.get_Item(TKey key)
at Telerik.XamarinForms.Common.XamarinToNativeControlExtensions.UpdateCollection[T,K] (Telerik.XamarinForms.Common.T nativeElement, Telerik.XamarinForms.Common.K xfЕlement, System.String propertyName, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00024] in <filename unknown>:0
Telerik.XamarinForms.DataControlsRenderer.iOS.ListViewRenderer.ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Telerik.XamarinForms.DataControls.RadListView.RaiseItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
System.Collections.ObjectModel.ObservableCollection<T>.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
System.Collections.ObjectModel.ObservableCollection<T>.OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index)
System.Collections.ObjectModel.ObservableCollection<T>.RemoveItem(int index)
System.Collections.ObjectModel.Collection<T>.Remove(T item)
MyApp.Data.ViewModel.OrdersViewModel.RemoveOrder(string orderId)

 

0
N Mackay
Top achievements
Rank 1
answered on 28 Jan 2016, 05:42 PM

I figured out the CustomRenderer for iOS to disable swipe left

 

public class CustomRadListRenderer : ListViewRenderer
    {
 
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs<Telerik.XamarinForms.DataControls.RadListView> e)
        {
            base.OnElementChanged(e);
            Control.CellSwipeLimits = new UIEdgeInsets(0, 60, 0, 0);
        }
    }

0
N Mackay
Top achievements
Rank 1
answered on 29 Jan 2016, 04:19 PM

Hi rosy,

I have opened a ticket for this and attached a repo project to the ticket.

Thanks,

Norman.

Tags
General Discussions
Asked by
N Mackay
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
N Mackay
Top achievements
Rank 1
Share this question
or