Beispiel #1
0
        async void OnManipulableControlManipulationStarted(object sender,
                                                           ManipulationStartedRoutedEventArgs args)
        {
            ManipulableContentControl manipulableControl = sender as ManipulableContentControl;
            Image image = manipulableControl.Content as Image;

            if ((ImageType)image.Tag == ImageType.Thumbnail)
            {
                // Set tag to transitioning
                image.Tag = ImageType.Transitioning;

                // Load the actual bitmap file
                StorageFile  storageFile = manipulableControl.Tag as StorageFile;
                BitmapSource newBitmap   = await LoadBitmapAsync(storageFile);

                // This is the case for a file that BitmapDecoder can't handle
                if (newBitmap != null)
                {
                    // Get the thumbnail from the Image element
                    BitmapSource oldBitmap = image.Source as BitmapSource;

                    // Find a ScaleTransform between old and new
                    double scale = 1;

                    if (oldBitmap.PixelWidth > oldBitmap.PixelHeight)
                    {
                        scale = (double)oldBitmap.PixelWidth / newBitmap.PixelWidth;
                    }
                    else
                    {
                        scale = (double)oldBitmap.PixelHeight / newBitmap.PixelHeight;
                    }

                    // Set properties on the Image element
                    image.Source          = newBitmap;
                    image.RenderTransform = new ScaleTransform
                    {
                        ScaleX = scale,
                        ScaleY = scale,
                    };
                }
                image.Tag = ImageType.Full;
            }
        }
Beispiel #2
0
        async void OnFolderListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
        {
            FolderItem folderItem = (sender as ListBox).SelectedItem as FolderItem;

            if (folderItem == null)
            {
                displayBorder.Child = null;
                return;
            }

            if (folderItem.DisplayGrid != null)
            {
                displayBorder.Child = folderItem.DisplayGrid;
                return;
            }

            Grid displayGrid = new Grid();

            folderItem.DisplayGrid = displayGrid;
            displayBorder.Child    = displayGrid;

            StorageFolder storageFolder = folderItem.StorageFolder;
            IReadOnlyList <StorageFile> storageFiles = await storageFolder.GetFilesAsync();

            foreach (StorageFile storageFile in storageFiles)
            {
                StorageItemThumbnail thumbnail =
                    await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem);

                BitmapSource bitmap = await LoadBitmapAsync(thumbnail);

                if (bitmap == null)
                {
                    continue;
                }

                // Create new Image element to display the thumbnail
                Image image = new Image
                {
                    Source  = bitmap,
                    Stretch = Stretch.None,
                    Tag     = ImageType.Thumbnail
                };

                // Create an initial CompositeTransform for the item
                CompositeTransform xform = new CompositeTransform();
                xform.TranslateX  = (displayBorder.ActualWidth - bitmap.PixelWidth) / 2;
                xform.TranslateY  = (displayBorder.ActualHeight - bitmap.PixelHeight) / 2;
                xform.TranslateX += 256 * (0.5 - rand.NextDouble());
                xform.TranslateY += 256 * (0.5 - rand.NextDouble());

                // Create the ManipulableContentControl for the Image
                ManipulableContentControl manipulableControl = new ManipulableContentControl(xform)
                {
                    Content = image,
                    Tag     = storageFile
                };
                manipulableControl.ManipulationStarted += OnManipulableControlManipulationStarted;

                // Put it in the Grid
                displayGrid.Children.Add(manipulableControl);
            }
        }