Mohammed Chami
.NET Developer | Content Creator
Mohammed Chami
.NET Developer | Content Creator

There are several ways to add icons to your Avalonia UI app. Here are the most common and effective methods:

<PackageReference Include="LucideAvalonia" />
xmlns:Icons="clr-namespace:LucideAvalonia;assembly=LucideAvalonia"
to search for icons link here
<UserControl xmlns:lucide="using:Lucide.Avalonia">
<StackPanel Spacing="10">
<!-- Simple icon -->
<Icons:Lucide Icon="Plus" Width="24" Height="24" />
<!-- Colored icon -->
<Icons:Lucide Icon="Check" Width="20" Height="20" Foreground="Green" />
<!-- In buttons -->
<Button>
<StackPanel Orientation="Horizontal" Spacing="5">
<Icons:Lucide Icon="Save" Width="16" Height="16" />
<TextBlock Text="Save Task" />
</StackPanel>
</Button>
<!-- More todo app relevant icons -->
<Icons:Lucide Icon="Calendar" Width="24" Height="24" />
<Icons:Lucide Icon="Clock" Width="24" Height="24" />
<Icons:Lucide Icon="User" Width="24" Height="24" />
<Icons:Lucide Icon="Settings" Width="24" Height="24" />
<Icons:Lucide Icon="Trash2" Width="24" Height="24" />
</StackPanel>
</UserControl>
<PackageReference Include="IconPacks.Avalonia"/>
<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://IconPacks.Avalonia/Icons.axaml" />
</Application.Styles>
for icons, it’s a GUI application, you can clone and run it:
https://github.com/MahApps/IconPacks.Browser
<UserControl xmlns:iconPacks="https://github.com/MahApps/IconPacks.Avalonia">
<StackPanel>
<iconPacks:PackIconBoxIcons Kind="RegularPlus" Width="24" Height="24" />
<iconPacks:PackIconBoxIcons Kind="RegularTrash" Width="24" Height="24" Foreground="Red" />
<iconPacks:PackIconBoxIcons Kind="RegularPencil" Width="24" Height="24" />
<iconPacks:PackIconBoxIcons Kind="RegularCheck" Width="24" Height="24" Foreground="Green" />
</StackPanel>
</UserControl>
Create a folder Assets/Icons/ and add your PNG files:
for SVG you need Avalonia.Svg package:
https://github.com/liwuqingxin/Avalonia.Svg
or you can convert it to png
<UserControl>
<StackPanel>
<!-- Direct SVG -->
<Image Source="..Assets/Icons/coding-icon.png" Width="24" Height="24" />
<!-- SVG in buttons -->
<Button>
<StackPanel Orientation="Horizontal" Spacing="5">
<Image Source="../Assets/Icons/plus.png" Width="16" Height="16" />
<TextBlock Text="Add Task" />
</StackPanel>
</Button>
</StackPanel>
</UserControl>
note that Avalonia does not support SVG so you need to use the Avalonia.Svg package.
<!-- In App.axaml or a style file -->
<Application.Resources>
<!-- Plus icon -->
<StreamGeometry x:Key="PlusIcon">M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z</StreamGeometry>
<!-- Check icon -->
<StreamGeometry x:Key="CheckIcon">M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z</StreamGeometry>
<!-- Delete icon -->
<StreamGeometry x:Key="DeleteIcon">M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z</StreamGeometry>
</Application.Resources>
<UserControl>
<StackPanel>
<!-- Using PathIcon -->
<PathIcon Data="{StaticResource PlusIcon}" Width="24" Height="24" Foreground="Blue" />
<PathIcon Data="{StaticResource CheckIcon}" Width="24" Height="24" Foreground="Green" />
<PathIcon Data="{StaticResource DeleteIcon}" Width="24" Height="24" Foreground="Red" />
</StackPanel>
</UserControl>
As your application grows, keeping all icons in App.axaml becomes messy. Here’s a much better approach – creating a dedicated Icons resource file.
Your project structure should now look like this:
Icons.axamlYourApp/
├── Views/
├── Assets/
├── ViewModels/
├── Resources/
│ └── Icons.axaml ← Your new file
├── App.axaml
└── Program.cs
Open your newly created Icons.axaml file and add your icon definitions:
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<!-- Add Controls for Previewer Here -->
</Border>
</Design.PreviewWith>
<!-- Define yours icons below -->
<Style>
<Style.Resources>
<StreamGeometry x:Key="search_regular">M11.5,2.75 C16.3324916,2.75 20.25,6.66750844 20.25,11.5 C20.25,13.6461673 19.4773285,15.6118676 18.1949905,17.1340957 L25.0303301Z...</StreamGeometry>
</Style.Resources>
</Style>
</Styles>
Now you need to tell Avalonia to load your icons. Update your App.axaml:
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="YourTodoApp.App">
<Application.Styles>
<FluentTheme />
<StyleInclude Source="Resources/Icons.axaml" />
</Application.Styles>
</Application>
Now comes the fun part, actually using your icons! Here’s how to use them in your Avalonia views:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="YourTodoApp.Views.TodoListView">
<StackPanel>
<PathIcon Data="{StaticResource AddIcon}" Width="16" Height="16" Foreground="White" />
<Button Background="Transparent" Padding="5">
<PathIcon Data="{StaticResource CheckIcon}" Width="20" Height="20" Foreground="Green" />
</Button>
<StackPanel Grid.Column="2" Orientation="Horizontal" Spacing="5" Margin="10,0">
<PathIcon Data="{StaticResource CalendarIcon}" Width="14" Height="14" Foreground="Gray" />
<TextBlock Text="Today" FontSize="12" Foreground="Gray" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</UserControl>
Here’s my honest recommendation based on different scenarios:
Choose PathIcon when:
Choose Lucide or MahaApps Icons when:
Choose Custom SVG or PNG when: