Esempio n. 1
0
        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);
                }
            }
        }
 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);    
         }
     }
 }