Class UserAvatar
The one avatar for a person: account menus, content authors and live-collaboration presence.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class UserAvatar : Avatar, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement
Remarks
UserAvatar is an Avatar that knows about people. It renders the profile image when
portrait is set, otherwise the name's initials on the identity's
color, so a person keeps one colour everywhere. It falls back to a
neutral ? when the identity has no name yet.
The initials colour is derived from the backdrop's own luminance rather than from the theme — that is autoLabelColor, which UserAvatar turns on. A themed foreground would vanish on some inputs: a pale identity colour in a light theme, a dark one in a dark theme.
With ring the avatar gets a thin neutral outline that thickens and turns the person's colour on hover — the presence affordance (who is this?), reusable by an AvatarGroup of live collaborators. The neutral outline and its hover thickness are USS, on tokens; only the person's colour comes from C#, because it is data rather than design.
An avatar shows only initials or an image, so set tooltip (typically the person's name) to
surface who it is on hover, and preferredTooltipPlacement to steer it — the App UI tooltip,
never an unstyled native one.
Everything else — size, variant — is inherited, so a AvatarGroup and a SizeContext drive a UserAvatar exactly as they drive a plain Avatar.
Examples
A presence avatar with a ring and a tooltip.
var avatar = new UserAvatar
{
identity = new UserIdentity
{
id = "u-42",
name = "Ada Lovelace",
color = new Color(0.05f, 0.43f, 0.78f),
},
ring = true,
size = Size.Lg,
tooltip = "Ada Lovelace",
};
UXML declaration — the identity is spelled out attribute by attribute.
<appui:UserAvatar user-id="u-42" user-name="Ada Lovelace" user-color="#0A6EC8" ring="true" size="Lg" />
Constructors
UserAvatar()
Default constructor.
Declaration
public UserAvatar()
Fields
ringUssClassName
The styling class carried while ring is enabled.
Declaration
public const string ringUssClassName = "appui-useravatar--ring"
Field Value
| Type | Description |
|---|---|
| string |
unknownLabel
The label shown when the identity has no name yet.
Declaration
public const string unknownLabel = "?"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The UserAvatar main styling class.
Declaration
public const string ussClassName = "appui-useravatar"
Field Value
| Type | Description |
|---|---|
| string |
Properties
identity
The person this avatar stands for.
Declaration
[CreateProperty]
public UserIdentity identity { get; set; }
Property Value
| Type | Description |
|---|---|
| UserIdentity |
Remarks
Setting it rewrites the initials, the backdrop colour and the portrait in one go. The individual userId, userName and userColor properties are the UXML-friendly view of the same state.
portrait
The person's profile image. Takes precedence over the initials when set.
Declaration
[CreateProperty]
public Background portrait { get; set; }
Property Value
| Type | Description |
|---|---|
| Background |
ring
Whether the avatar carries the presence ring.
Declaration
[CreateProperty]
[UxmlAttribute("ring")]
public bool ring { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
A thin neutral outline that thickens on hover and adopts userColor while hovered. With no colour on the identity, the neutral token colour stays.
userColor
The person's identity colour, used as the initials backdrop.
Declaration
[CreateProperty]
[UxmlAttribute("user-color")]
public Optional<Color> userColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Optional<Color> |
Remarks
Not a theme colour: it identifies a person, not a surface. Leave it unset to keep the component's default surface styling.
userId
The person's stable identifier.
Declaration
[CreateProperty]
[UxmlAttribute("user-id")]
[Header("User Avatar")]
public string userId { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
userName
The person's display name. Drives the initials, and is null until it resolves.
Declaration
[CreateProperty]
[UxmlAttribute("user-name")]
public string userName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
GetInitials(string)
Two-letter initials from a display name, for an avatar fallback.
Declaration
public static string GetInitials(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The display name. May be null. |
Returns
| Type | Description |
|---|---|
| string | The initials, in upper case. |
Remarks
"Ada Lovelace" becomes "AL", "Madonna" becomes "MA", and an empty or whitespace-only name becomes an empty string, which the avatar then renders as unknownLabel.