From bc8a0eadfb44e40db5b7e2827e5cfc6b6ca6214c Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Fri, 15 May 2026 11:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=A5=E5=91=8A=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=9B=BE=E5=83=8F=E8=87=AA=E9=80=82=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XplorePlane/Controls/ZoomableImageViewer.cs | 36 ++++++--------------- XplorePlane/Themes/Generic.xaml | 2 +- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/XplorePlane/Controls/ZoomableImageViewer.cs b/XplorePlane/Controls/ZoomableImageViewer.cs index 8e920ee..ac931ed 100644 --- a/XplorePlane/Controls/ZoomableImageViewer.cs +++ b/XplorePlane/Controls/ZoomableImageViewer.cs @@ -237,33 +237,13 @@ namespace XplorePlane.Controls private void ExecuteFitToView() { - if (_imageElement == null || _containerBorder == null || Source == null) + if (_imageElement == null || Source == null) return; - double containerWidth = _containerBorder.ActualWidth; - double containerHeight = _containerBorder.ActualHeight; - - if (containerWidth <= 0 || containerHeight <= 0) - return; - - double imageWidth = Source.PixelWidth; - double imageHeight = Source.PixelHeight; - - if (imageWidth <= 0 || imageHeight <= 0) - return; - - // Calculate scale to fit - double scaleX = containerWidth / imageWidth; - double scaleY = containerHeight / imageHeight; - double scale = Math.Min(scaleX, scaleY); - - // Clamp to min/max - scale = Math.Max(MinScale, Math.Min(MaxScale, scale)); - - _scaleTransform.ScaleX = scale; - _scaleTransform.ScaleY = scale; - - // Center the image + // With Stretch="Uniform", the Image control already fits the image to the container. + // FitToView simply resets the transform to identity (scale=1, translate=0). + _scaleTransform.ScaleX = 1.0; + _scaleTransform.ScaleY = 1.0; _translateTransform.X = 0; _translateTransform.Y = 0; } @@ -279,8 +259,10 @@ namespace XplorePlane.Controls if (containerWidth <= 0 || containerHeight <= 0) return; - double imageWidth = Source.PixelWidth * _scaleTransform.ScaleX; - double imageHeight = Source.PixelHeight * _scaleTransform.ScaleY; + // With Stretch="Uniform", the Image control's ActualWidth/Height represents + // the displayed size at scale=1. Multiply by current scale for actual rendered size. + double imageWidth = _imageElement.ActualWidth * _scaleTransform.ScaleX; + double imageHeight = _imageElement.ActualHeight * _scaleTransform.ScaleY; // Calculate bounds double maxOffsetX = Math.Max(0, (imageWidth - containerWidth) / 2); diff --git a/XplorePlane/Themes/Generic.xaml b/XplorePlane/Themes/Generic.xaml index 547a088..4347305 100644 --- a/XplorePlane/Themes/Generic.xaml +++ b/XplorePlane/Themes/Generic.xaml @@ -143,7 +143,7 @@ VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality" Source="{TemplateBinding Source}" - Stretch="None" /> + Stretch="Uniform" />