locked
Sqlite image and observable collection RRS feed

  • Question

  • I am using SQLite for a database with a class called Library. I store and image in the database from a byte[] array. Saving the data is no problem as the byte[] array saves to a blob column in the database.

    When I read this back in I am using an image converter which converts my image from the database back into a bitmapsource in my viewmodel and then I bind the source to the image on the view.

    This all works perfectly for one record from the database, however, on another page I am showing the library items in a listview using an observable collection ObservableCollection<Library>

    My problem is, how do I set the image source in the observable collection, I cant use another property in my class because SQLite complains


    Mal

    Saturday, February 1, 2014 2:56 PM

Answers

  • Ok got it to work by doing this

                var list = new ObservableCollection<LibraryObject>();
                var connection = new SQLiteAsyncConnection(_dbPath);
                libraryobjects = new ObservableCollection<LibraryObject>(await connection.QueryAsync<LibraryObject>("select * from library"));
                foreach (LibraryObject obj in libraryobjects)
                {
                    obj.SiteImageSource = obj.SiteImage.AsBitmapImage();
                }
                return libraryobjects;


    Mal

    • Marked as answer by MalBall Saturday, February 1, 2014 4:45 PM
    Saturday, February 1, 2014 4:45 PM

All replies

  • Have 2 classes one for the data access and one for display.  copy the data into the class for display and databank to it
    Saturday, February 1, 2014 3:34 PM
  • Have 2 classes one for the data access and one for display.  copy the data into the class for display and databank to it
    Thanks for the answer, I considered that but thought there might be a more elegant way to do it

    Mal

    Saturday, February 1, 2014 3:56 PM
  • Ok got it to work by doing this

                var list = new ObservableCollection<LibraryObject>();
                var connection = new SQLiteAsyncConnection(_dbPath);
                libraryobjects = new ObservableCollection<LibraryObject>(await connection.QueryAsync<LibraryObject>("select * from library"));
                foreach (LibraryObject obj in libraryobjects)
                {
                    obj.SiteImageSource = obj.SiteImage.AsBitmapImage();
                }
                return libraryobjects;


    Mal

    • Marked as answer by MalBall Saturday, February 1, 2014 4:45 PM
    Saturday, February 1, 2014 4:45 PM