/**
         * Creates the list of ImageViewModels of the photos in this gallery. Once the list is created, loads
         * their thumbnails asynchronously.
         */
        private void InitAndLoadAllImages()
        {
            _images.Clear();

            // Initialize all the image vms first without loading the images. This way,
            // the whole gallery will be available and navigatable to in the slideshow
            // view.
            for (int i = 0; i < _gallery.Count; i++)
            {
                // 2nd argument is 0 so that it only loads the image once
                ImageViewModel vm = new ImageViewModel(_gallery[i], 0, ThumbnailHeight);
                _images.Add(vm);
            }

            LoadAllImages();
        }
示例#2
0
        /**
         * Initializes the cache of images as an array. Initially, the index of the current image is the 2nd position
         * in the array. As the user moves left & right through the slideshow, the index will move left & right along
         * with it, wrapping at the end as with a circular buffer. The cached images nearby the current image will be
         * in the same relative position to the current image's position in the array.
         */
        private void InitCache()
        {
            int cacheIndex = 0;

            // Create each cache position for images before the current one
            for (int i = 1; i <= BACK_CACHE_NUM; i++)
            {
                // Which image in the gallery do we load into the cache
                int galleryIndex = CurrentIndex - i;
                if (galleryIndex < 0)
                {
                    galleryIndex += _galleryItems.Count();
                }

                // Create the VM which holds the image & subscribe to property change events
                _imageCache[cacheIndex] = new ImageViewModel(_galleryItems[galleryIndex], 256, 0);
                _imageCache[cacheIndex].PropertyChanged += new PropertyChangedEventHandler(Child_OnPropertyChanged);
                cacheIndex++;
            }


            // Create a cache position for the current image
            _imageCacheCurrIndex = cacheIndex;
            // Create the VM which holds the image & subscribe to property change events
            _imageCache[cacheIndex] = new ImageViewModel(_galleryItems[CurrentIndex], 256, 0);
            _imageCache[cacheIndex].PropertyChanged += new PropertyChangedEventHandler(Child_OnPropertyChanged);
            cacheIndex++;


            // Create each cache position for images after the current one
            for (int i = 1; i <= FORWARD_CACHE_NUM; i++)
            {
                // Which image in the gallery do we load into the cache
                int galleryIndex = CurrentIndex + i;
                if (galleryIndex >= _galleryItems.Count())
                {
                    galleryIndex -= _galleryItems.Count();
                }

                // Create the VM which holds the image & subscribe to property change events
                _imageCache[cacheIndex] = new ImageViewModel(_galleryItems[galleryIndex], 256, 0);
                _imageCache[cacheIndex].PropertyChanged += new PropertyChangedEventHandler(Child_OnPropertyChanged);
                cacheIndex++;
            }
        }
        /// <summary>
        /// Opens the given Photo in a new page.
        /// </summary>
        /// <param name="parameter">The Photo instance to open.</param>
        public void OpenImage(object parameter)
        {
            Photo p = parameter as Photo;

            // Get a list of all the currently visible images
            List <ImageViewModel> list   = ImagesView.OfType <ImageViewModel>().ToList();
            List <Photo>          photos = ImageViewModel.GetPhotoList(list);

            // Get the clicked on photo's index in the list of Photos
            int index = 0;

            for (int i = 0; i < list.Count; i++)
            {
                if (p == list[i].Photo)
                {
                    index = i;
                }
            }

            // Create a new page to view the clicked image
            ImageSlideshowViewModel imagePage = new ImageSlideshowViewModel(photos, index);

            _navigator.NewPage(imagePage);
        }