/// <summary> /// MainViewModel constructor /// </summary> public MainViewModel(double titleHeight) { this.Pages = new ObservableCollection<ImagesPage>(); // Add spacer to top of page var spacerPage = new ImagesPage(null); spacerPage.Grid.Height = titleHeight; this.Pages.Add(spacerPage); // Initiail load if pages this.LoadPages(2, true); }
/// <summary> /// Loads image page that contains four rows and four columns and can contain up to 16 images /// </summary> /// <param name="isPopular">If this is set to true, page will be marked as popular</param> public void LoadNextPage(bool isPopular = false) { // Work around for known _bug in the media framework. Hits the static constructors // so the user does not need to go to the picture hub first. // ReSharper disable ReturnValueOfPureMethodIsNotUsed MediaPlayer.Queue.ToString(); // ReSharper restore ReturnValueOfPureMethodIsNotUsed var mediaLib = new MediaLibrary(); var models = new List<ImageModel>(); var pictures = mediaLib.Pictures .OrderByDescending(p => p.Date) .Skip(this.imagesLoaded) .Take(isPopular ? ImagesPerPagePopular : ImagesPerPage); // Go through all pictures foreach (var picture in pictures) { // Create image model var model = new ImageModel() { Name = picture.Name, Picture = picture }; // Create bitmap image and set source to thumbnail stream var bitmap = new BitmapImage(); bitmap.SetSource(picture.GetThumbnail()); model.ImageSource = bitmap; // Add mdoel to current list models.Add(model); } if (models.Count > 0) { // Increase loaded images number to match real count and add model to the pages list this.imagesLoaded += isPopular ? ImagesPerPagePopular : ImagesPerPage; var imagesPage = new ImagesPage(models, isPopular); imagesPage.OnImageTap += ImagesPageImageTap; this.Pages.Add(imagesPage); } }