Merge pull request #729 from irihitech/wrap_count
Add new readonly property: LineCount for ElasticWrapPanel
This commit is contained in:
@@ -11,10 +11,8 @@ public class ElasticWrapPanel : WrapPanel
|
|||||||
{
|
{
|
||||||
static ElasticWrapPanel()
|
static ElasticWrapPanel()
|
||||||
{
|
{
|
||||||
IsFillHorizontalProperty.Changed.AddClassHandler<Control>(OnIsFillPropertyChanged);
|
|
||||||
IsFillVerticalProperty.Changed.AddClassHandler<Control>(OnIsFillPropertyChanged);
|
|
||||||
|
|
||||||
AffectsMeasure<ElasticWrapPanel>(IsFillHorizontalProperty, IsFillVerticalProperty);
|
AffectsMeasure<ElasticWrapPanel>(IsFillHorizontalProperty, IsFillVerticalProperty);
|
||||||
|
AffectsArrange<ElasticWrapPanel>(IsFillHorizontalProperty, IsFillVerticalProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region AttachedProperty
|
#region AttachedProperty
|
||||||
@@ -60,9 +58,15 @@ public class ElasticWrapPanel : WrapPanel
|
|||||||
public static readonly StyledProperty<bool> IsFillVerticalProperty =
|
public static readonly StyledProperty<bool> IsFillVerticalProperty =
|
||||||
AvaloniaProperty.Register<ElasticWrapPanel, bool>(nameof(IsFillVertical));
|
AvaloniaProperty.Register<ElasticWrapPanel, bool>(nameof(IsFillVertical));
|
||||||
|
|
||||||
private static void OnIsFillPropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
private int _lineCount;
|
||||||
|
|
||||||
|
public static readonly DirectProperty<ElasticWrapPanel, int> LineCountProperty = AvaloniaProperty.RegisterDirect<ElasticWrapPanel, int>(
|
||||||
|
nameof(LineCount), o => o.LineCount);
|
||||||
|
|
||||||
|
public int LineCount
|
||||||
{
|
{
|
||||||
(d as ElasticWrapPanel)?.InvalidateMeasure();
|
get => _lineCount;
|
||||||
|
private set => SetAndRaise(LineCountProperty, ref _lineCount, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -376,7 +380,7 @@ public class ElasticWrapPanel : WrapPanel
|
|||||||
lineUIEles.Clear();
|
lineUIEles.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LineCount = lineUVCollection.Count;
|
||||||
lineUVCollection.ForEach(col => col.Dispose());
|
lineUVCollection.ForEach(col => col.Dispose());
|
||||||
lineUVCollection.Clear();
|
lineUVCollection.Clear();
|
||||||
return finalSize;
|
return finalSize;
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Shapes;
|
||||||
|
using Avalonia.Headless.XUnit;
|
||||||
|
using Avalonia.Layout;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace HeadlessTest.Ursa.Controls.ElasticWrapPanelTests;
|
||||||
|
|
||||||
|
public class Tests
|
||||||
|
{
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void LineCount_Correct()
|
||||||
|
{
|
||||||
|
var window = new Window() { };
|
||||||
|
var panel = new ElasticWrapPanel
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
Height = 200,
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
};
|
||||||
|
window.Content = panel;
|
||||||
|
window.Show();
|
||||||
|
Assert.Equal(0, panel.LineCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void LineCount_Correct_1()
|
||||||
|
{
|
||||||
|
var window = new Window() { };
|
||||||
|
var panel = new ElasticWrapPanel
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
Height = 200,
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
};
|
||||||
|
var rect = new Rectangle
|
||||||
|
{
|
||||||
|
Width = 100,
|
||||||
|
Height = 100,
|
||||||
|
};
|
||||||
|
panel.Children.Add(rect);
|
||||||
|
window.Content = panel;
|
||||||
|
window.Show();
|
||||||
|
Assert.Equal(1, panel.LineCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AvaloniaFact]
|
||||||
|
public void LineCount_Correct_2()
|
||||||
|
{
|
||||||
|
var window = new Window() { };
|
||||||
|
var panel = new ElasticWrapPanel
|
||||||
|
{
|
||||||
|
Width = 200,
|
||||||
|
Height = 200,
|
||||||
|
Orientation = Orientation.Horizontal,
|
||||||
|
};
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
var rect = new Rectangle
|
||||||
|
{
|
||||||
|
Width = 100,
|
||||||
|
Height = 100,
|
||||||
|
};
|
||||||
|
panel.Children.Add(rect);
|
||||||
|
}
|
||||||
|
window.Content = panel;
|
||||||
|
window.Show();
|
||||||
|
Assert.Equal(2, panel.LineCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user