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?
For sure,
this is the exception:
foreach (DataRow dr in dt.Rows)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:
{
Application.Current.Dispatcher.Invoke(() => Mappen.Add(new clsProduktionslinienPlanungEintrag(dr)));
}
public ObservableCollection<clsProduktionslinienPlanungEintrag> Mappen { get; set; }The
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;
}
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.