답변을 찾았습니다. Canvas 컨트롤을 사용하여 하나의 상위 컨테이너에 배치 된 현재 Image 컨트롤의 비율과 시프트를 계산합니다. 나는 정적 방법으로 도우미에서이 코드를 배치 :
Width = box.Size.Width * _horizontalRatio,
Height = box.Size.Height * _verticalRatio,
Canvas.SetLeft(contentControl, _horizontalShift + box.TopLeft.X * _horizontalRatio);
Canvas.SetTop(contentControl, _verticalShift + box.TopLeft.Y * _verticalRatio);
: 다음
ImageHelper.CalculateRatios(this.LayoutCanvas, (BitmapImage)this.ImageFingersBitmap.Source, ref _horizontalShift, ref _verticalShift, ref _horizontalRatio, ref _verticalRatio);
내가 내 경계의 크기와 위치를 계산하는 데 사용
public static void CalculateRatios(Panel panel, BitmapImage image, ref double horizontalShift, ref double verticalShift, ref double horizontalRatio, ref double verticalRatio)
{
panel.UpdateLayout();
var ratioSource = image.PixelWidth/image.PixelHeight;
var ratioImage = panel.ActualWidth/panel.ActualHeight;
Size pictureInControlSize;
if (ratioSource > ratioImage) // image control extended in height
{
pictureInControlSize = new Size(panel.ActualWidth, panel.ActualWidth/ratioSource);
}
else if (ratioSource < ratioImage) // image control extended in width
{
pictureInControlSize = new Size(panel.ActualHeight * ratioSource, panel.ActualHeight);
}
else // image control have the same proportions
{
pictureInControlSize = new Size(panel.ActualWidth, panel.ActualHeight);
}
horizontalShift = (panel.ActualWidth - pictureInControlSize.Width)/2d;
verticalShift = (panel.ActualHeight - pictureInControlSize.Height)/2d;
horizontalRatio = pictureInControlSize.Width/image.PixelWidth;
verticalRatio = pictureInControlSize.Height/image.PixelHeight;
}
우선은 비율을 계산