Avatar
Wisej.NET 4.2.0+
An Avatar is the round portrait that stands for a person, a team or an account: a photo when there is one, two initials on a colour derived from the name when there is not, and an optional presence dot in the corner. It can also show a label and a sub-label beside the portrait, which turns it into the "name and role" block found in headers, assignee fields and comment threads.
AvatarGroup shows several portraits overlapping in a row, followed by a "+N" count for the ones that do not fit — the members of a project, the watchers of a ticket, the people on a shift. Each portrait and the count are clickable.
Both replace the usual PictureBox plus Label arrangement, with the fallbacks already worked out: a missing or broken image falls back to initials, and an empty name shows a neutral placeholder.
For a complete list of properties, methods, and events, see the API documentation of Avatar and AvatarGroup.
Features
Image or Initials
Text is the person's name. The avatar derives up to two initials from it — the first letter of the first and the last name — and, while AutoColor is true (the default), picks one of the theme's avatar colours from the name, so the same person always gets the same colour.
To show a photo, set ImageSource to a URL or a theme image name, or Image to an Image instance; Image wins when both are set. Images remain owned by your code and are never disposed by the control. If the image cannot be loaded, the initials are shown instead.
Size and Shape
AvatarSize is the portrait's diameter in pixels, from 16 to 256 (40 by default). The AvatarSizePreset enumeration names the standard sizes — XS 24, S 32, M 40, L 56, XL 72 — and is cast to int. AvatarSize does not change the control's Size: the portrait is drawn inside it, and a control with labels needs to be wider than the portrait.
Shape is Circle (the default), Rounded or Square.
Presence
Presence adds a status dot: Online, Away, Busy or Offline, or None. The status is also announced to screen readers; OnlineText, AwayText, BusyText and OfflineText override the built-in, localized wording.
Labels
Label and SubLabel are shown beside the portrait — typically the name and the role or department. In an AvatarGroup they are not displayed inline; they become the portrait's tooltip and accessible name instead.
AvatarGroup
Items is an AvatarItemCollection of AvatarItem objects, which carry the same Text, ImageSource, Image, Shape, Presence, AutoColor, Label and SubLabel as the Avatar, plus a Tag for your own data that stays on the server. Changing an item updates the group.
MaxVisible limits how many portraits are drawn (five by default); the rest are summed up in the overflow count. AvatarSize sets the diameter of every portrait and Overlap how many pixels each one tucks under its neighbour (10 by default).
ItemClick is raised with an AvatarItemEventArgs holding the Item and its Index; OverflowClick is raised when the "+N" count is clicked.
How To
Show the Current User
An avatar with labels needs a Size wide enough for them; the portrait itself stays at AvatarSize.
var user = new Avatar
{
Text = "Saoirse Kovač",
Label = "Saoirse Kovač",
SubLabel = "Finance · Accounts Payable",
ImageSource = "Images/Employees/skovac.jpg",
Presence = AvatarPresence.Online,
AvatarSize = (int)AvatarSizePreset.M,
Size = new Size(260, 48)
};
user.Click += (s, e) => ShowProfile("skovac");
this.Controls.Add(user);
Show the Members of a Project
Store the record in Tag, show at most four portraits, and open the full list from the overflow count.
this.avatarGroup1.MaxVisible = 4;
this.avatarGroup1.AvatarSize = (int)AvatarSizePreset.S;
foreach (var employee in project.Members)
{
this.avatarGroup1.Items.Add(new AvatarItem
{
Text = employee.FullName,
Label = employee.FullName,
SubLabel = employee.Title,
Presence = employee.IsOnline ? AvatarPresence.Online : AvatarPresence.Offline,
Tag = employee
});
}
this.avatarGroup1.ItemClick += (s, e) => ShowEmployee((Employee)e.Item.Tag);
this.avatarGroup1.OverflowClick += (s, e) => ShowProjectMembers(project);
Update Presence Live
Items notify their group of changes, so updating one item redraws the group without rebuilding it.
void OnPresenceChanged(int employeeId, bool online)
{
foreach (AvatarItem item in this.avatarGroup1.Items)
{
if (((Employee)item.Tag).Id == employeeId)
item.Presence = online ? AvatarPresence.Online : AvatarPresence.Away;
}
}
Advanced
JavaScript Widget
| Item | Description |
|---|---|
| Class name | "wisej.web.Avatar", "wisej.web.AvatarGroup" |
| Theme appearance | "avatar", "avatargroup", see Themes. |
| Child components | Avatar: "portrait" holds "face", which shows "initials" or "image", and the "presence" dot. "labels" holds "label" and "sublabel". AvatarGroup draws each portrait and the overflow count as an "avatar" widget. See JavaScript. |