From 66ad32f52a18c4b6a22aed711042eac8a6e9bf92 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Wed, 6 Mar 2024 14:33:35 +0800 Subject: [PATCH] fix: image viewer crash issue. --- .../HandyControl_Shared/Controls/Image/ImageViewer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs b/src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs index 9ae80e84..8865004d 100644 --- a/src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs +++ b/src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs @@ -962,11 +962,10 @@ public class ImageViewer : Control private void OnUriChanged(Uri newValue) { - if (newValue is not null) + ImageSource = newValue is not null ? GetBitmapFrame(newValue) : null; + if (ImageSource is not null && newValue.IsAbsoluteUri) { - ImageSource = GetBitmapFrame(newValue); ImgPath = newValue.AbsolutePath; - if (File.Exists(ImgPath)) { ImgSize = new FileInfo(ImgPath).Length; @@ -974,8 +973,8 @@ public class ImageViewer : Control } else { - ImageSource = null; ImgPath = string.Empty; + ImgSize = 0; } static BitmapFrame GetBitmapFrame(Uri source)