Пример #1
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);
            }
        }