private void Preview_Click(object sender, EventArgs e) { if (Img != null) { var detail = new ImgDetail(Img); detail.ShowDialog(); } }
void BrdFrame_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) { if (e.PinchManipulation == null) { //Drag double horizontalChange = e.DeltaManipulation.Translation.X; double verticalChange = e.DeltaManipulation.Translation.Y; //좌측으로 if (horizontalChange < 0 && protectDirection != DragDirection.Left) { transform.TranslateX += horizontalChange; transform.TranslateY += verticalChange; protectDirection = DragDirection.None; } //우측으로 else if (horizontalChange > 0 && protectDirection != DragDirection.Right) { transform.TranslateX += horizontalChange; transform.TranslateY += verticalChange; protectDirection = DragDirection.None; } else if (verticalChange < 0 && protectDirection != DragDirection.Top) { //위로 transform.TranslateX += horizontalChange; transform.TranslateY += verticalChange; protectDirection = DragDirection.None; } else if (verticalChange > 0 && protectDirection != DragDirection.Bottom) { //아래로 transform.TranslateX += horizontalChange; transform.TranslateY += verticalChange; protectDirection = DragDirection.None; } else { return; } //일단 움직이면 축소 가능하도록 설정 canZoomOut = true; GeneralTransform gtf = ImgDetail.TransformToVisual(ImgFrame); Point pt = gtf.Transform(new Point(ImgDetail.ActualWidth, ImgDetail.ActualHeight)); //좌측선 if (pt.X < innerRect.Left) { transform.TranslateX += innerRect.Left - pt.X; protectDirection = DragDirection.Left; canZoomOut = false; } //상단선 if (pt.Y < innerRect.Top) { transform.TranslateY += innerRect.Top - pt.Y; protectDirection = DragDirection.Top; canZoomOut = false; } gtf = ImgFrame.TransformToVisual(ImgDetail); pt = gtf.Transform(new Point(innerRect.Left + innerRect.Width, innerRect.Top + innerRect.Height)); //우측선 if (pt.X < 0) { transform.TranslateX += pt.X; protectDirection = DragDirection.Right; canZoomOut = false; } //하단선 if (pt.Y < 0) { transform.TranslateY += pt.Y; protectDirection = DragDirection.Bottom; canZoomOut = false; } } else { //Pinch double distanceRatio = e.PinchManipulation.CumulativeScale; Size scale = new Size(currentScale.X * distanceRatio, currentScale.Y * distanceRatio); bool isZoomIn = scale.Width > transform.ScaleX; if (isZoomIn) { canZoomOut = true; protectDirection = DragDirection.None; } if (scale.Width <= SCALE_MAX && (canZoomOut || isZoomIn)) { //축소일때 최소영역보다 이하이면 축소하지 않음 if (ImgDetail.ActualWidth * scale.Width >= innerRect.Width / 2 && ImgDetail.ActualHeight * scale.Height >= innerRect.Height / 2) { transform.ScaleX = scale.Width; transform.ScaleY = scale.Height; Point inPoint = new Point(innerRect.Left + innerRect.Width, innerRect.Top + innerRect.Height); CompensationPinch(distanceRatio, ImgFrame, ImgDetail, inPoint, 0, true); CompensationPinch(distanceRatio, ImgFrame, ImgDetail, inPoint, 0, false); inPoint = new Point(ImgDetail.ActualWidth, ImgDetail.ActualHeight); CompensationPinch(distanceRatio, ImgDetail, ImgFrame, inPoint, innerRect.Left, true); CompensationPinch(distanceRatio, ImgDetail, ImgFrame, inPoint, innerRect.Top, false); } } } }