Desperately trying to get the index of a listview which is fed by an observable collection from a separate viewmodel class.
in my mainpage, which holds the listview xaml(called "mainlist") i have the onitemselected method which needs to give me the index.
I've tried all so far without any luck.
This is the only code that applies but it gives me null reference expception as well:
int index = (mainlist.ItemsSource as List<MainListItem>).IndexOf(e.SelectedItem as MainListItem);
Saying Object reference not set to an instance of an object.
What am i missing here?
This is my mainviewmodel.cs that creates the observablecollection
private ObservableCollection<MainListItem> _list;
public ObservableCollection<MainListItem> List
{
get { return _list; }
set
{
_list = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(List)));
}
}