diff --git a/src/Uno.UI.Composition/Composition/ShapeVisual.cs b/src/Uno.UI.Composition/Composition/ShapeVisual.cs index 96d4c63f23d0..5cef2a5b1844 100644 --- a/src/Uno.UI.Composition/Composition/ShapeVisual.cs +++ b/src/Uno.UI.Composition/Composition/ShapeVisual.cs @@ -1,27 +1,38 @@ #nullable enable -namespace Windows.UI.Composition +namespace Windows.UI.Composition; + +public partial class ShapeVisual : ContainerVisual { - public partial class ShapeVisual : ContainerVisual + private CompositionViewBox? _viewBox; + private CompositionShapeCollection? _shapes; + + public ShapeVisual(Compositor compositor) + : base(compositor) { - private CompositionViewBox? _viewBox; - private CompositionShapeCollection? _shapes; + } - public ShapeVisual(Compositor compositor) - : base(compositor) - { - // Add this as context for the shape collection so we get - // notified about changes in the shapes object graph. - OnCompositionPropertyChanged(null, Shapes, nameof(Shapes)); - } + public CompositionViewBox? ViewBox + { + get => _viewBox; + set => SetProperty(ref _viewBox, value); + } - public CompositionViewBox? ViewBox + // This is lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure. + public CompositionShapeCollection Shapes + { + get { - get => _viewBox; - set => SetProperty(ref _viewBox, value); - } + if (_shapes is null) + { + _shapes = new CompositionShapeCollection(Compositor, this); - // This ia lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure. - public CompositionShapeCollection Shapes => _shapes ??= new CompositionShapeCollection(Compositor, this); + // Add this as context for the shape collection so we get + // notified about changes in the shapes object graph. + OnCompositionPropertyChanged(null, _shapes, nameof(Shapes)); + } + + return _shapes; + } } }