diff --git a/demo/Ursa.Demo/Pages/AvatarDemo.axaml b/demo/Ursa.Demo/Pages/AvatarDemo.axaml
index bf36a75..7605f6b 100644
--- a/demo/Ursa.Demo/Pages/AvatarDemo.axaml
+++ b/demo/Ursa.Demo/Pages/AvatarDemo.axaml
@@ -65,7 +65,7 @@
-
+
diff --git a/src/Ursa/Controls/Avatar/AvatarGroup.cs b/src/Ursa/Controls/Avatar/AvatarGroup.cs
index 340b2c6..0609367 100644
--- a/src/Ursa/Controls/Avatar/AvatarGroup.cs
+++ b/src/Ursa/Controls/Avatar/AvatarGroup.cs
@@ -10,14 +10,14 @@ public class AvatarGroup : ItemsControl
private static readonly FuncTemplate DefaultPanel = new(() => new AvatarGroupPanel());
- public static readonly StyledProperty MaxCountProperty = AvaloniaProperty.Register(
+ public static readonly StyledProperty MaxCountProperty = AvaloniaProperty.Register(
nameof(MaxCount));
public static readonly StyledProperty OverlapFromProperty =
AvaloniaProperty.Register(
nameof(OverlapFrom), defaultValue: OverlapFromType.Start);
- public int MaxCount
+ public int? MaxCount
{
get => GetValue(MaxCountProperty);
set => SetValue(MaxCountProperty, value);
diff --git a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs
index cfc24fb..9ad3e97 100644
--- a/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs
+++ b/src/Ursa/Controls/Avatar/AvatarGroupPanel.cs
@@ -11,16 +11,19 @@ public class AvatarGroupPanel : Panel
Size size = new Size();
availableSize = availableSize.WithWidth(double.PositiveInfinity);
var children = Children;
- if (children.Count > 0)
+ if (children.Count <= 0) return size;
+ children[0].Measure(availableSize);
+ Size first = children[0].DesiredSize;
+ var group = this.GetLogicalAncestors().OfType().FirstOrDefault();
+ var count = children.Count;
+ if (group?.MaxCount is not null && group.MaxCount >= 0)
{
- children[0].Measure(availableSize);
- Size first = children[0].DesiredSize;
- var width = first.Width + first.Width * (children.Count - 1) * 0.75;
- size = size.WithWidth(width);
- size = size.WithHeight(first.Height);
+ count = group.MaxCount.Value + 1;
}
- size = size.WithWidth(size.Width);
+ var width = first.Width + first.Width * (count - 1) * 0.75;
+ size = size.WithWidth(width);
+ size = size.WithHeight(first.Height);
return size;
}
@@ -28,10 +31,18 @@ public class AvatarGroupPanel : Panel
{
Rect rect = new Rect(finalSize);
double num = 0d;
+ var children = Children;
var group = this.GetLogicalAncestors().OfType().FirstOrDefault();
var overlapFrom = group?.OverlapFrom;
- var children = Children;
- for (var i = 0; i < children.Count; i++)
+ int? maxCount = null;
+ var count = children.Count;
+ if (group?.MaxCount is not null && group.MaxCount >= 0)
+ {
+ maxCount = group.MaxCount;
+ count = maxCount.Value + 1;
+ }
+
+ for (var i = 0; i < count; i++)
{
if (overlapFrom is OverlapFromType.Start)
{
@@ -49,6 +60,14 @@ public class AvatarGroupPanel : Panel
children[i].Arrange(rect);
}
+ if (maxCount is not null && children.Count > 0)
+ {
+ if (children[maxCount.Value] is Avatar avatar)
+ {
+ avatar.Content = $"+{children.Count - maxCount}";
+ }
+ }
+
return finalSize;
}
}
\ No newline at end of file