I'm pretty new to Silverlight and C#, i've just made a little application that allows the user to add books (title, author and description), they can also search on these fields with an autocompletebox.

Now, I've only used an observable collection once and the only way I know how to use it is to use buttons (one to save and one to load the collection). However, I wish to be able to have the collection load itself when the application is started so I can then remove the button.

Can someone please advise on how I can do this? I am using MVVM as well, in case that's important.

Extra brownie points if you can also tell me how to save the collection upon exiting the application (but this is a nice to have)

Massive thanks in advance
Dom

Here is some code, sorry for not posting it before.

MainViewModel

```
using System.Collections.ObjectModel;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;
using PTL.Legal.CRM.Silverlight.Common.Commanding;

namespace BookSearch1._1.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private BookViewModel _selectedBook;

        #region Constructor
        public MainViewModel()
        {
            SubmitCommand = new DelegateCommand<object>(AddBook);
            SaveCommand = new DelegateCommand<object>(SaveResults);
            LoadCommand = new DelegateCommand<object>(LoadResults);
            Books = new ObservableCollection<BookViewModel>();
            SelectedBook = new BookViewModel();
        }

        #endregion

        #region Properties

        public void AddBook(object obj)
        {
            Books.Add(SelectedBook);
        }

        public ICommand SubmitCommand { get; set; }
        public ICommand SaveCommand { get; set; }
        public ICommand LoadCommand { get; set; }

        public BookViewModel SelectedBook
        {
            get { return _selectedBook; }
            set { _selectedBook = value; OnPropertyChanged("SelectedBook"); }
        }

        public void SaveResults(object obj)
        {
            //using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    using (IsolatedStorageFileStream isoStream =
            //        new IsolatedStorageFileStream("MainSettings.xml", FileMode.Create, isf))
            //    {
            //        var settings = new XmlWriterSettings();
            //        settings.Indent = true;

            //        using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
            //        {
            //            writer.WriteStartElement("UserSettings");

            //            foreach (string result in Books)
            //            {
            //                writer.WriteStartElement("Result");
            //                writer.WriteString(result);
            //                writer.WriteEndElement();
            //            }

            //            writer.WriteEndElement();

            //            writer.Flush();
            //        }
            //    }
            //}

            //MessageBox.Show("Settings applied.");
        }

        public void LoadResults(object obj)
        {
            //using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    var storStream =
            //        new StreamReader(new IsolatedStorageFileStream("MainSettings.xml", FileMode.Open, isf));

            //    var xmlReaderSettings = new XmlReaderSettings
            //                                {
            //                                    IgnoreWhitespace = true,
            //                                    IgnoreComments = true,
            //                                    CheckCharacters = true
            //                                };

            //    XmlReader xmlReader = XmlReader.Create(storStream, xmlReaderSettings);

            //    while (xmlReader.Read())
            //    {
            //        if (xmlReader.NodeType == XmlNodeType.Element &&
            //            "Result" == xmlReader.LocalName)
            //        {
            //            Books.Add(xmlReader.ReadElementContentAsString());
            //        }
            //    }

            //    xmlReader.Close();
            //}
        }

        #endregion

        public AutoCompleteFilterPredicate<object> CustomFilter 
        { 
            get 
            {
                return new AutoCompleteFilterPredicate<object>(SearchBooks);
            }
        }

        bool SearchBooks(string search, object value)
        {
            // Cast the value to an Employee.
            var books = value as BookViewModel;
            if (books != null)
            {
                // Look for a match in the first and last names.
                if (SelectedBook.Title.ToLower().Contains(search.ToLower()) || SelectedBook.Author.ToLower().Contains(search.ToLower()) || SelectedBook.Description.ToLower().Contains(search.ToLower()))
                    return true;

            }
            // If no match, return false.
            return false;
        }

        public ObservableCollection<BookViewModel> Books { get; set; }

    }
}

```