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" />