I'm using Prism 6.3 to build a simple cloud client with seafile.
After the user logs in, I navigate to a sidebar in a side region (SidebarRegion). OnNavigatedTo are the libraries loaded in a collection and displayed.
When the selected library changes, I navigate to a new ItemsView instance (ContentRegion) and load the items (from the library) so they can also be displayed.
If now clicked on an item, I navigate to another side region to display detailed information about the item.
public SeafDirEntry SelectedItem
{
get { return _selectedItem; }
set
{
if (!SetProperty(ref _selectedItem, value) || value == null)
return;
var parameter = new NavigationParameters {{ "item", _selectedItem }};
_regionManager.RequestNavigate(_regionNames.InfoBarRegion, new Uri("ItemInfoView", UriKind.Relative), parameter);
}
}
There's also a delete button, which is hooked to a command which deletes the item
Now, after the item/file is deleted from the server, I hooked up the PubSubEvent to reload the items from the library with the RefreshItemsAsync() method.
After the items collection is overwritten, the PropertyChangedevent throws a NullReferenceException, even if I try this:
public ObservableCollection<SeafDirEntry> Items
{
get { return _items; }
set
{
if (value == _items)
return;
_items = value;
RaisePropertyChanged(); // <- throws here
// SetProperty(ref _items, value); <- same result
}
}
I tried also to remove the item from the collection with the item as payload of the PubSubEvent, but it also throws an NullReferenceException at _items.Remove(itemFromPayload).
Even if I refresh the collection manually by a button, same result.
The ItemsViewModel gets only created once per library and resists even after switching between them, so the reference should exists.
What did I miss out here?