0

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?

Benjamin Diele
  • 1,177
  • 1
  • 10
  • 26
  • 1
    `ObservableCollection` already implements `IList` :) – Lucas Trzesniewski Nov 07 '14 at 19:37
  • 1
    can't you just create an observabecollection and populate it with the list from your library instead of reinventing the wheel? e.g. the code that creates a playlist will grab a list from your library and convert to observablecollection for your playlist – failedprogramming Nov 07 '14 at 20:20
  • Can you open a ticket in the bitbucket project? I think it's doable and maybe it can be included it in the next release – redent84 Nov 10 '14 at 10:39
  • @redent84 I've sorta hacked it together myself for testing, but I will add a ticket when I get home tonight :) – Benjamin Diele Nov 10 '14 at 10:40

1 Answers1

1

SQLite-Net Extensions already supports ObservableList as *ToMany property. It shouldn't be needed any workaround anymore.

redent84
  • 18,901
  • 4
  • 62
  • 85