private void Window_Loaded(object sender, RoutedEventArgs e) { // Instantiate the data service context. context = new PhotoDataContainer(svcUri); // Call the method to get photos from the data service. GetPhotosFromService(MergeOption.AppendOnly); }
// Provides data to the ViewModel with the provided objects, // which enables us to restore the ViewModel after reactivation. public void LoadData(PhotoDataContainer context, DataServiceCollection <PhotoInfo> photos) { this._context = context; this.Photos = photos; IsDataLoaded = true; }
// Loads data from the data service for the first time. public void LoadData() { // Instantiate the context and binding collection. _context = new PhotoDataContainer(svcRootUri); Photos = new DataServiceCollection <PhotoInfo>(_context); // Load the data from the PhotoInfo feed. Photos.LoadAsync(new Uri("/PhotoInfo", UriKind.Relative)); }
// Restores the ViewModel state from the supplied state dictionary. public void RestoreState(IDictionary <string, object> dictionary) { // Create a dictionary to hold any stored binding collections. Dictionary <string, object> collections; // Get the stored DataServiceState object from the dictionary. var state = dictionary["DataServiceState"] as DataServiceState; if (state != null) { // Restore the context and binding collections. PhotoDataContainer context = state.Restore(out collections) as PhotoDataContainer; // Get the binding collection of Title objects. DataServiceCollection <PhotoInfo> photos = collections["Photos"] as DataServiceCollection <PhotoInfo>; // Initialize the application with stored data. App.ViewModel.LoadData(context, photos); dictionary.Remove("DataServiceState"); } }