diff --git a/src/AvaloniaEdit/Utils/ExtensionMethods.cs b/src/AvaloniaEdit/Utils/ExtensionMethods.cs index 7fe4b896..fd5b0900 100644 --- a/src/AvaloniaEdit/Utils/ExtensionMethods.cs +++ b/src/AvaloniaEdit/Utils/ExtensionMethods.cs @@ -224,6 +224,9 @@ public static Point SnapToDevicePixels(this Point p, IVisual targetVisual) // Create a matrix to translate from control coordinates to device coordinates. var m = targetVisual.TransformToVisual((Control)root) * Matrix.CreateScale(scaling); + if (m == null) + return p; + // Translate the point to device coordinates. var devicePoint = p.Transform(m.Value);