/// The methods provided in this section are simply used to allow /// NavigationHelper to respond to the page's navigation methods. /// /// Page specific logic should be placed in event handlers for the /// <see cref="GridCS.Common.NavigationHelper.LoadState"/> /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>. /// The navigation parameter is available in the LoadState method /// in addition to page state preserved during an earlier session. protected override void OnNavigatedTo(NavigationEventArgs e) { _project = (CanvasProject)e.Parameter; _navigationHelper.OnNavigatedTo(e); Task returnTask = BindImages(_project); returnTask.ContinueWith(_ => { }); DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView(); dataTransferManager.DataRequested += DataTransferManager_DataRequested; }
/// <summary> /// Invoked when an item is clicked. /// </summary> /// <param name="sender">The GridView (or ListView when the application is snapped) /// displaying the item clicked.</param> /// <param name="e">Event data that describes the item clicked.</param> async void ItemView_ItemClick(object sender, ItemClickEventArgs e) { var project = ((CanvasProject)e.ClickedItem); if (project.Id == -1) { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.FileTypeFilter.Add(".png"); filePicker.FileTypeFilter.Add(".jpg"); filePicker.FileTypeFilter.Add(".jpeg"); filePicker.ViewMode = PickerViewMode.Thumbnail; filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; filePicker.SettingsIdentifier = "imagePicker"; filePicker.CommitButtonText = "Select Files for Collage"; IReadOnlyCollection <StorageFile> files = await filePicker.PickMultipleFilesAsync(); if (files.Count > 0) { project.ImagePath = files.First().Path; project = new CanvasProject { Name = "NewCanvas.canvas", FilePath = files.First().Path, ImagePath = files.First().Path + ".canvasimage", Id = -1 }; int count = 1; project.Pictures = new List <CanvasPicture>(); foreach (var item in files) { CanvasPicture pict = new CanvasPicture { Id = count++, ImagePath = item.Path, SourceFile = item }; project.Pictures.Add(pict); } } } this.Frame.Navigate(typeof(SplitPage), project); }
private async Task BindImages(CanvasProject project) { collageCanvas.AllowDrop = true; Random degrees = new Random(5); int maxWidth = (int)Window.Current.Bounds.Width; int maxCols = (int)maxWidth / 300; int row = 0, col = 0; for (int i = 0; i < project.Pictures.Count; i++) { var canvasPicture = project.Pictures[i]; Image image = new Image(); using (var fileStream = await canvasPicture.SourceFile.OpenAsync(FileAccessMode.Read)) { var sourceImage = new BitmapImage(); sourceImage.SetSource(fileStream); image.Source = sourceImage; image.Tag = canvasPicture; image.Height = 300; image.Height = 200; image.Stretch = Stretch.Uniform; image.IsHitTestVisible = true; image.IsTapEnabled = true; TransformableContainer container = new TransformableContainer(); container.Content = image; container.Transform.Rotation = degrees.Next(-15, 15); col = (col + 1 > maxCols) ? 0 : col + 1; row = (col + 1 > maxCols) && (i != 0) ? row + 1 : row; container.Transform.TranslateX = col * 300; container.Transform.TranslateY = row * 200; container.Transform.CenterX = 150; container.Transform.CenterY = 100; container.CanvasPicture = canvasPicture; collageCanvas.Children.Add(container); } } }