/// <summary> /// Update the scroll viewer of the thumbnail panel /// </summary> private void UpdateScrollViewer(bool isScrollDown, double thumbnailHeight) { if (isScrollDown) { if (ThumbNailScrollViewer.ViewportHeight < (_currentIndex * (thumbnailHeight + DefaultMargin20) + ViewPortRoundingConstant)) { var total = (_currentIndex * (thumbnailHeight + DefaultMargin20) + ViewPortRoundingConstant); ThumbNailScrollViewer.ChangeView(null, total, 1.0F, false); } } else { if (ThumbNailScrollViewer.ViewportHeight > 0) { var total = (_currentIndex * (thumbnailHeight + DefaultMargin20)) - (thumbnailHeight + DefaultMargin20); ThumbNailScrollViewer.ChangeView(null, total, 1.0F, false); } } }
/// <summary> /// Update the layout for thumbnail and main views for mobile environment /// </summary> /// <param name="presentation">The presentation to be viewed</param> /// <returns></returns> private async Task UpdateMobileLayout(IPresentation presentation) { borderHeader.Visibility = Visibility.Visible; loadingRing.Visibility = Visibility.Visible; loadingRing.IsActive = true; ThumbNailScrollViewer.Visibility = Visibility.Collapsed; LoadingStatusCanvas.Visibility = Visibility.Visible; ThumbNailScrollViewer.ChangeView(null, 1, null); int renderedSlides = 0; for (int i = 0; i < _presentation.Slides.Count; i++) { ISlide slide = _presentation.Slides[i]; await ConvertSlide(slide); renderedSlides++; if (renderedSlides == 4 || slide.SlideNumber == _slideCount) { for (int j = slide.SlideNumber - (renderedSlides - 1); j <= slide.SlideNumber; j++) { await AddMobileThumbnailView(j); } renderedSlides = 0; loadingRing.Visibility = Visibility.Collapsed; } if ((_slideCount >= 4 && slide.SlideNumber == 4) || _slideCount < 4) { loadingRing.Visibility = Visibility.Collapsed; loadingRing.IsActive = false; ThumbNailScrollViewer.Visibility = Visibility.Visible; //LoadingStatusCanvas.Visibility = Visibility.Visible; } } LoadingStatusCanvas.Visibility = Visibility.Collapsed; }
/// <summary> /// Convert the slides to images and update the layout /// </summary> private async Task Render() { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.Desktop; openPicker.FileTypeFilter.Add(".pptx"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file == null) { if (!_isWindowsPhone) { TempThumbNailScrollViewer.Visibility = Visibility.Collapsed; ThumbNailScrollViewer.Visibility = Visibility.Visible; MainViewImageGrid.Visibility = Visibility.Visible; loadingRing.IsActive = false; loadingRing.Visibility = Visibility.Collapsed; } return; } if (!_isWindowsPhone) { CancelRunningTask(); _currentIndex = -1; ThumbNailScrollViewer.ChangeView(null, 1, null); } if (_isWindowsPhone) { ThumbNailScrollViewer.Visibility = Visibility.Collapsed; ThumbNailScrollViewer.ChangeView(null, 1, null); loadingRing.Visibility = Visibility.Visible; loadingRing.IsActive = true; } Dispose(); _isTaskRunning = true; //Open the presentation stream and retrieve it in the presentation instance. Stream pptxStream = file.OpenStreamForReadAsync().Result; TitleTextBlock.Text = file.Name; LoadPresentation(pptxStream); if (!_isWindowsPhone) { foreach (ISlide slide in _presentation.Slides) { if (_cancellationToken.IsCancellationRequested) { return; } string filePath = await ConvertSlide(slide); RowDefinition row = new RowDefinition(); ThumbnailGrid.RowDefinitions.Add(row); if (_cancellationToken.IsCancellationRequested) { return; } if (_presentation.Slides[0].SlideNumber == 0) { UpdateThumbnailGrid(filePath, slide.SlideNumber + 1, _cancellationToken); } else { UpdateThumbnailGrid(filePath, slide.SlideNumber, _cancellationToken); } if ((_presentation.Slides.Count >= 5 && slide.SlideNumber == 5) || _presentation.Slides.Count < 5) { TempThumbNailScrollViewer.Visibility = Visibility.Collapsed; ThumbNailScrollViewer.Visibility = Visibility.Visible; MainViewImageGrid.Visibility = Visibility.Visible; loadingRing.IsActive = false; loadingRing.Visibility = Visibility.Collapsed; } } } else if (_isWindowsPhone) { if (_cancellationToken.IsCancellationRequested) { return; } LoadingStatusCanvas.Visibility = Visibility.Collapsed; int renderedSlides = 0; for (int i = 0; i < _slideCount; i++) { ISlide slide = _presentation.Slides[i]; if (_cancellationToken.IsCancellationRequested) { return; } await ConvertSlide(slide); renderedSlides++; if (renderedSlides == 4 || slide.SlideNumber == _slideCount) { for (int j = slide.SlideNumber - (renderedSlides - 1); j <= slide.SlideNumber; j++) { await AddMobileThumbnailView(j); } renderedSlides = 0; } if ((_slideCount >= 4 && slide.SlideNumber == 4) || _slideCount < 4) { loadingRing.Visibility = Visibility.Collapsed; loadingRing.IsActive = false; ThumbNailScrollViewer.Visibility = Visibility.Visible; LoadingStatusCanvas.Visibility = Visibility.Visible; } } LoadingStatusCanvas.Visibility = Visibility.Collapsed; } pptxStream.Dispose(); _isTaskRunning = false; }