Repository navigation
Usage Guide
This guide covers all the ways to display and customize icons. See Getting Started for initial setup.
The Icon control is the primary way to display an icon:
<i:Icon Value="fa-solid fa-anchor" />Icon size is controlled by FontSize (inherited from TemplatedControl):
<i:Icon Value="fa-solid fa-anchor" FontSize="32" />If not set, FontSize is inherited from the parent control.
Use the Foreground property:
<i:Icon Value="fa-solid fa-anchor" Foreground="DodgerBlue" />Use Attached.Icon to add an icon to any ContentControl (Button, ToggleButton, etc.):
<Button i:Attached.Icon="fa-solid fa-save" />This replaces the button's Content with an Icon control. The icon inherits the button's Foreground and FontSize.
Use MenuItem.Icon to set the icon on a menu item:
<MenuItem Header="Settings" i:MenuItem.Icon="fa-solid fa-gear" />Use IconImage as the source of an Avalonia Image control for more control over rendering:
<Image Width="48" Height="48">
<Image.Source>
<i:IconImage Value="fa-solid fa-anchor" Brush="DodgerBlue" />
</Image.Source>
</Image>IconImage properties:
-
Value-- the icon identifier string -
Brush-- fill color (defaults to black) -
Pen-- stroke pen (defaults to no stroke)
Two built-in animations are available via the Animation property:
Smooth continuous 360-degree rotation (2-second loop):
<i:Icon Value="fa-solid fa-sync" Animation="Spin" />Stepped rotation in 8 discrete increments (2-second loop), giving a "ticking" effect:
<i:Icon Value="fa-solid fa-spinner" Animation="Pulse" />You can style icons using standard Avalonia style selectors:
<Style Selector="i|Icon">
<Setter Property="FontSize" Value="20" />
<Setter Property="Foreground" Value="Gray" />
</Style>Target specific animations:
<Style Selector="i|Icon[Animation=Spin]">
<Setter Property="Foreground" Value="Green" />
</Style>Bind the Value property to dynamically change icons:
<i:Icon Value="{Binding CurrentIcon}" FontSize="24" />public class MyViewModel : INotifyPropertyChanged
{
private string _currentIcon = "fa-solid fa-play";
public string CurrentIcon
{
get => _currentIcon;
set { _currentIcon = value; OnPropertyChanged(); }
}
// Toggle between play and pause
public void Toggle()
{
CurrentIcon = CurrentIcon.Contains("play")
? "fa-solid fa-pause"
: "fa-solid fa-play";
}
}- Icon Packs -- naming conventions and how to browse available icons
- API Reference -- full list of classes and properties