I'm using SQLiteNet-Extensions to implement a OneToMany
relation between a Playlist
and an IList
of Track
.
At the moment the only supported collection types by the library are List
and array (I changed the library to allow IList
as a List
).
Now I want to be able to be notified whenever my collection of Tracks is modified (add, remove, clear), but ObservableCollection
is not allowed by the library (and I don't want to change the library too much as well).
This means I'm trying to recreate an ObservableCollection
as follows:
class ObservableIList<T> : IList<T>, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
private List<T> list = new List<T>();
public void Add(T item)
{
list.Add(item);
OnPropertyChanged("magical property name");
}
....
}
So that my Playlist
would look as follows:
class Playlist
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Title { get; set; }
[Indexed]
public Boolean isCurrent { get; set; }
[OneToMany]
public ObservableIList<Track> Tracks { get; set; }
}
This seems like it should work, except that I don't know what propertyName
I should use when adding a new Track
to my ObservableList
?
Or am I going the completely wrong way at this?
SQLite-Net Extensions already supports ObservableList
as *ToMany property. It shouldn't be needed any workaround anymore.