In This Article

Avatar Group

Use an AvatarGroup to render multiple Avatar controls.

Screenshot

AvatarGroup with image-based avatars and some items overflowed

Presentation

Use the ItemLength property to define the width and height of each Avatar in the group.

By default, each avatar will slightly overlap with the avatar that appears before it. Use the OverlapPercentage property to define the extent of the overlap. The default value is 0.2 for a 20% overlap.

Overflow

Individual Avatar controls can optionally be overflowed when there is not enough room to display them all inline. When overflow is necessary, a button is added at the end of the group that, when clicked, will display the additional items in a popup.

Overflow is set to Popup by default. Set the OverflowKind property to None to disable overflow behavior.

By default, the group will display as many avatars as possible in the space available, but the MaxInlineCount property can be set to limit how many are displayed before overflowing.

The overflow button indicates the number of overflowed items. Use the OverflowStringFormat property to customize how the count is formatted. The default is "+{0}", where {0} is the placeholder for the current value of OverflowedItemCount (e.g., "+9").

Configuring Avatar Items

The AvatarGroup is an ItemsControl for Avatar controls.

Individual instances of Avatar can be directly defined as the ItemsSource as shown below:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...

<actipro:AvatarGroup ... >
	<actipro:Avatar Description="Han Solo" />
	<actipro:Avatar Description="Leia Organa" />
	<actipro:Avatar Description="Luke Skywalker" />
	...
</actipro:AvatarGroup>

The ItemsSource can also be defined as non-Avatar items. In this scenario, each item is automatically wrapped in an Avatar container with the original item as the DataContext. Each Avatar instance will need to be configured to bind its properties to the underlying DataContext. This can be done using an ItemContainerTheme as shown in the following example where ItemsSource is bound to a collection of view models:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...

<actipro:AvatarGroup ItemsSource="{Binding SomeUserCollection}" ... >
	<actipro:AvatarGroup.ItemContainerTheme>
		<ControlTheme TargetType="actipro:Avatar" BasedOn="{StaticResource {x:Type actipro:Avatar}}" x:DataType="someNamespace:SomeUser">
			<Setter Property="Description" Value="{Binding UserName}" />
			<Setter Property="Content" Value="{Binding ProfileImage}" />
		</ControlTheme>
	</actipro:AvatarGroup.ItemContainerTheme>
</actipro:AvatarGroup>

Working with Large Datasets

The built-in overflow behavior of AvatarGroup is not designed for use with large data sets where the number of overflowed items cannot be reasonably displayed in a popup.

For example, consider a scenario where an open source project wants to display the avatars of contributing users. For some projects, that could be thousands of users that would never display properly in a popup!

One option is to limit the number of items included in the dataset. For example, instead of listing all contributors to the open source project, the dataset could be limited to the top 20 contributors.

Another option is to configure the AvatarGroup to disable built-in overflow support and present an alternate UI. The following example disables overflow and places a custom link next to the control which could be used to display a more appropriate view of all the contributors.

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...

<StackPanel Orientation="Horizontal">
	<actipro:AvatarGroup OverflowKind="None" ItemsSource="{Binding Contributors}">
		...
	</actipro:AvatarGroup>
	<actipro:HyperlinkTextBlock Text="+ 58 contributors" Command="{ShowContributorsCommand}"/>
</StackPanel>