From ff65f4f44197ecbd4dc1e38a88a2c05903c69268 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sun, 13 Jul 2025 15:32:33 +0800 Subject: [PATCH] feat: add new readonly property: LineCount. add a demo of consuming this property. demo will be reverted. --- demo/Ursa.Demo/Pages/ElasticWrapPanelDemo.axaml | 10 +++++++++- src/Ursa/Controls/ElasticWrapPanel.cs | 16 ++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/demo/Ursa.Demo/Pages/ElasticWrapPanelDemo.axaml b/demo/Ursa.Demo/Pages/ElasticWrapPanelDemo.axaml index 10040d3..c8f9057 100644 --- a/demo/Ursa.Demo/Pages/ElasticWrapPanelDemo.axaml +++ b/demo/Ursa.Demo/Pages/ElasticWrapPanelDemo.axaml @@ -104,11 +104,19 @@ - + + + + diff --git a/src/Ursa/Controls/ElasticWrapPanel.cs b/src/Ursa/Controls/ElasticWrapPanel.cs index b971709..6fb71b6 100644 --- a/src/Ursa/Controls/ElasticWrapPanel.cs +++ b/src/Ursa/Controls/ElasticWrapPanel.cs @@ -11,10 +11,8 @@ public class ElasticWrapPanel : WrapPanel { static ElasticWrapPanel() { - IsFillHorizontalProperty.Changed.AddClassHandler(OnIsFillPropertyChanged); - IsFillVerticalProperty.Changed.AddClassHandler(OnIsFillPropertyChanged); - AffectsMeasure(IsFillHorizontalProperty, IsFillVerticalProperty); + AffectsArrange(IsFillHorizontalProperty, IsFillVerticalProperty); } #region AttachedProperty @@ -60,9 +58,15 @@ public class ElasticWrapPanel : WrapPanel public static readonly StyledProperty IsFillVerticalProperty = AvaloniaProperty.Register(nameof(IsFillVertical)); - private static void OnIsFillPropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) + private int _lineCount; + + public static readonly DirectProperty LineCountProperty = AvaloniaProperty.RegisterDirect( + nameof(LineCount), o => o.LineCount); + + public int LineCount { - (d as ElasticWrapPanel)?.InvalidateMeasure(); + get => _lineCount; + private set => SetAndRaise(LineCountProperty, ref _lineCount, value); } #endregion @@ -376,7 +380,7 @@ public class ElasticWrapPanel : WrapPanel lineUIEles.Clear(); } } - + LineCount = lineUVCollection.Count; lineUVCollection.ForEach(col => col.Dispose()); lineUVCollection.Clear(); return finalSize;