From f2efed0d13c49afcd930f42350fa7a33738cd129 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 26 Dec 2024 17:24:02 +0800 Subject: [PATCH] fix: fix image binding to stretch initialization issue. --- src/Ursa/Controls/ImageViewer/ImageViewer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ursa/Controls/ImageViewer/ImageViewer.cs b/src/Ursa/Controls/ImageViewer/ImageViewer.cs index e0abde2..021151f 100644 --- a/src/Ursa/Controls/ImageViewer/ImageViewer.cs +++ b/src/Ursa/Controls/ImageViewer/ImageViewer.cs @@ -163,8 +163,9 @@ public class ImageViewer: TemplatedControl private void OnStretchChanged(AvaloniaPropertyChangedEventArgs args) { + if (_image is null) return; var stretch = args.GetNewValue(); - Scale = GetScaleRatio(Width / _image!.Width, Height / _image!.Height, stretch); + Scale = GetScaleRatio(Width / _image.Width, Height / _image.Height, stretch); _sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale; }