Im having a hard time with the following error: I have a listview that is binded to an observable collection. Lets say it looks like this:
XAMl:
<ListView ItemsSource="{Binding myCollection}" SelectedItem="{Binding selectedItem}">
ViewModel:
private Field selecteditem;
public Field selectedItem {
get { return selecteditem; }
set
{
selecteditem = value;
}
... //other code parts
myCollection = customClass.fillCollection(selectedLightColor, selectedDarkColor);
When i click on an item it is selected. When i click on another that is the selected one. This is totally okay. However at a certain point i need to recreate the whole observable collection that is connected to this listview.
If i didnt select anything it recreates the collection perfectly.
But, when i have a selected item it throws a System.NullReferenceException error to the property that is binded to the SelectedItem of the listview.
For the recreation im using the same code mentioned above (myCollection = customClass...)
I cant find a solution that solves the problem.
I have tried myCollection.Clear() and also selectedItem = null, but the error remained the same.
Im glad to hear any help!
I tried to reproduce the problem you describe, but it didn't work for me.
My example:
Perhaps you missed an important detail of your implementation in the explanations, which is the cause of the error you described.
Try changing my simple example to reproduce your problem.
BaseInpc and RelayCommand classes.
Source Code Archive: freasy.7z