RadCardView Binding

1 Answer 206 Views
CardView
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Benedikt asked on 16 Nov 2021, 03:01 PM

Hi guys,

I tried to use a RadCardView wich I wanted to replace a RadListBox, so I bound it to the same Collection in my ViewModel.

This collection is a ObservableCollection. To this collection are items added and removed from code behind from time to time. 
But when this happens I get a nullreference exception.
In the Listbox everything is fine...

And the exception of the CardView is the same with or without a Dispatcher.

 

Does anyone have an idea what could solve this?

Martin Ivanov
Telerik team
commented on 17 Nov 2021, 01:53 PM

Can you share the exception details - like the exact message and the stacktrace? Also, can you show how do you add and remove items in code-behind?
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 17 Nov 2021, 02:05 PM

For sure,

this is the exception:

System.NullReferenceException
  HResult=0x80004003
  Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
  Quelle = Telerik.Windows.Controls
  Stapelüberwachung:
   at Telerik.Windows.Controls.Layouts.WrapLayout.InvalidateGroupLines(Object item, GroupInfo groupInfo)
   at Telerik.Windows.Controls.Layouts.WrapLayout.OnItemsChangedCore(Object source, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Controls.Layouts.LayoutControl.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChangedWithAdjustedArgs(NotifyCollectionChangedEventArgs originalArguments, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
   at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at DispoTelerik2.ViewModels.clsMappenProduktionslinienPlanungViewModel.<>c__DisplayClass4_0.<BackgroundWorkerAktualisierenWork>b__0() in C:\Users\luzb\Documents\Visual Studio 2019\Projects\DispoTelerik2\Klassen\ViewModels\clsMappenProduktionslinienPlanungViewModel.cs:line 46

It happens at this point:

                foreach (DataRow dr in dt.Rows)
                {
                    Application.Current.Dispatcher.Invoke(() => Mappen.Add(new clsProduktionslinienPlanungEintrag(dr)));
                }


The 

        public ObservableCollection<clsProduktionslinienPlanungEintrag> Mappen { get; set; }

Gets initialized empty in the constructor.
Later (and when sumone presses a reload button) the collection gets filled in a BackgropundWorkker

        private void BackgroundWorkerAktualisierenWork(object sender, DoWorkEventArgs e)
        {
            DataTable dt = new DataTable();
            DataTable dtPlan = new DataTable();

            if (selProduktionslinienBereich != null)
            {
                if (selProduktionslinienBereich.ID == 28)
                {
                    dt = clsDaten.GibProduktionslinienMappenFälligMKMWithTermin(Datum);
                    dtPlan = clsDaten.GibProduktionslinienMappenPlanMKMWithTermin(Datum);
                }

                foreach (DataRow dr in dt.Rows)
                {
                    Application.Current.Dispatcher.Invoke(() => Mappen.Add(new clsProduktionslinienPlanungEintrag(dr)));
                }

                foreach (DataRow dr in dtPlan.Rows)
                {
                    Application.Current.Dispatcher.Invoke(() => MappenGeordnet.Add(new clsProduktionslinienPlanungEintrag(dr)));
                }

                object[] Data = clsDaten.GibPlanzellenProduktionslinien(Datum, selProduktionslinienBereich.ID);

                Planzellen = (decimal)Data[0];
                Gesperrt = (bool)Data[1];
            }

            Gespeichert = true;

            ZeitraumOpen = false;
        }
Martin Ivanov
Telerik team
commented on 22 Nov 2021, 11:43 AM

I've tested this, but I couldn't reproduce the error. Can you check the attached project and tell me if I am missing anything?
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 23 Nov 2021, 02:32 PM

Hi, I've modified your project, so that now comes the same error when the Button is cklicked.
The reason seems to be, that the source is empty at start.

If I add an item in the inizialication, I can add without error. If the source starts empty, it doesnt work.

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 26 Nov 2021, 02:33 PM

Hello Benedikt,

Thank you for the modified project it helped a great deal.

It looks like there is some initialization logic that has not been executed and trying to add an item, when there are non in the card view, causes the exception. I have logged this bug in our Public Feedback Portal. You can track its progress, vote, comment, and subscribe for status change alerts by following this link. I have also updated your Telerik Points for bringing this issue to our attention.

As the issue is in the core layout logic of the control, I am not able to provide a workaround.

I hope this clears things up. Should you have further questions or feedback, do write back.

Regards,
Ivan Petrov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
CardView
Asked by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Ivan Petrov
Telerik team
Share this question
or