/// <summary> /// 初始化照片墙 /// </summary> private void InitPhotoWall() { if (this.listPhoto.Count != HorizontalCount * VerticalCount) { return; } int count = 0; int partBgWidth = (int)((this.mainCanvas.ActualWidth / HorizontalCount - ShowImageWidth / HorizontalCount) / 2); int partBgHeight = (int)((this.mainCanvas.ActualHeight / VerticalCount - ShowImageHeight / VerticalCount) / 2); for (int i = 0; i < HorizontalCount; i++) { for (int j = 0; j < VerticalCount; j++) { photos[i, j] = new MyPhotoControl(random.Next(-15, 15)) { Width = ShowImageWidth / HorizontalCount, Height = ShowImageHeight / VerticalCount, PuzzleImage = listPhoto[count], StopPoint = new Point(i * (this.mainCanvas.ActualWidth / HorizontalCount) + partBgWidth, j * (this.mainCanvas.ActualHeight / VerticalCount) + partBgHeight), }; photos[i, j].MouseLeftButtonDown += MyPhotoControl_MouseLeftButtonDown; Canvas.SetLeft(photos[i, j], i * (this.mainCanvas.ActualWidth / HorizontalCount) + partBgWidth); Canvas.SetTop(photos[i, j], j * (this.mainCanvas.ActualHeight / VerticalCount) + partBgHeight); this.mainCanvas.Children.Add(photos[i, j]); count++; } } }
private void MyPhotoControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (IsShowImage) { UnInitShowPhoto(); } else { MyPhotoControl myPhoto = sender as MyPhotoControl; ShowImage = myPhoto.PuzzleImage; zoom = ShowImage.PixelWidth / ShowImageWidth * 1.0; InitShowPhoto(); } }