diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs index a8a7109c735..8bad6f2e683 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs @@ -166,13 +166,21 @@ private void SourceImage_ManipulationDelta(object sender, ManipulationDeltaRoute private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e) { - if (Source == null) + if (Source == null || !IsValidRect(CanvasRect)) { return; } - UpdateImageLayout(); - UpdateMaskArea(); + if (_lazyInitImageLayoutAction != null) + { + _lazyInitImageLayoutAction.Invoke(); + _lazyInitImageLayoutAction = null; + } + else + { + UpdateImageLayout(); + UpdateMaskArea(); + } } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs index 47f87baed84..3eadd206d02 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs @@ -23,6 +23,12 @@ public partial class ImageCropper /// Whether animation is enabled. private void InitImageLayout(bool animate = false) { + if (!IsValidRect(CanvasRect)) + { + _lazyInitImageLayoutAction = () => InitImageLayout(animate); + return; + } + if (Source != null) { _restrictedCropRect = new Rect(0, 0, Source.PixelWidth, Source.PixelHeight); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs index 60ed065fbdd..cf68b2ea686 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs @@ -59,6 +59,7 @@ public partial class ImageCropper : Control private RectangleGeometry _outerGeometry; private Geometry _innerGeometry; private TimeSpan _animationDuration = TimeSpan.FromSeconds(0.3); + private Action _lazyInitImageLayoutAction; /// /// Initializes a new instance of the class.