From 3e3f11d84f1d05fdf4ac4e9595648517b99438c5 Mon Sep 17 00:00:00 2001 From: Evan Ruiz Date: Wed, 29 Jan 2025 17:50:28 -0500 Subject: [PATCH] Path Geometry update fix for 4748 bug rerender on change for paths segments (#18025) * Add failing Path Geometry update test #4748 [BUG] Rerender on change for Paths, Segments and e.g. Failing Test * Fixes failing Path Geometry update test Fixes #4748 [BUG] Rerender on change for Paths, Segments and e.g. --- src/Avalonia.Base/Media/PathGeometry.cs | 2 +- .../Media/PathGeometryTests.cs | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/Avalonia.Base.UnitTests/Media/PathGeometryTests.cs diff --git a/src/Avalonia.Base/Media/PathGeometry.cs b/src/Avalonia.Base/Media/PathGeometry.cs index bdfbfadce4..c07535c00b 100644 --- a/src/Avalonia.Base/Media/PathGeometry.cs +++ b/src/Avalonia.Base/Media/PathGeometry.cs @@ -35,7 +35,7 @@ namespace Avalonia.Media /// public PathGeometry() { - _figures = new PathFigures(); + Figures = new PathFigures(); } /// diff --git a/tests/Avalonia.Base.UnitTests/Media/PathGeometryTests.cs b/tests/Avalonia.Base.UnitTests/Media/PathGeometryTests.cs new file mode 100644 index 0000000000..9648187e61 --- /dev/null +++ b/tests/Avalonia.Base.UnitTests/Media/PathGeometryTests.cs @@ -0,0 +1,32 @@ +using Avalonia.Media; +using Xunit; + +namespace Avalonia.Base.UnitTests.Media; + +public class PathGeometryTests +{ + [Fact] + public void PathGeometry_Triggers_Invalidation_On_Figures_Add() + { + var segment = new PolyLineSegment() + { + Points = [new Point(1, 1), new Point(2, 2)] + }; + + var figure = new PathFigure() + { + Segments = [segment], + IsClosed = false, + IsFilled = false, + }; + + var target = new PathGeometry(); + + var changed = false; + + target.Changed += (_, _) => { changed = true; }; + + target.Figures?.Add(figure); + Assert.True(changed); + } +}