Primary APIs:
PathIconIconElementPathIcon.DataPropertyGeometry.Parse(...)StreamGeometry.Parse(...)PathGeometry.Parse(...)Geometry.TransformReference source files:
src/Avalonia.Controls/PathIcon.cssrc/Avalonia.Controls/IconElement.cssrc/Avalonia.Themes.Fluent/Controls/PathIcon.xamlsrc/Avalonia.Themes.Simple/Controls/PathIcon.xamlsrc/Avalonia.Base/Media/Geometry.cssrc/Avalonia.Base/Media/StreamGeometry.cssrc/Avalonia.Base/Media/PathGeometry.csPathIcon is a lightweight templated icon control:
PathIcon.Data contains the vector geometry.Path inside a Viewbox.Foreground drives fill color.Width/Height define icon size.Practical implication:
PathIcon over raw Path when representing semantic UI icons.Store icon geometry in shared resources:
<Application.Resources>
<StreamGeometry x:Key="Icon.Settings">M14 9.5C11.5 9.5 9.5 11.5 9.5 14C9.5 16.5 11.5 18.5 14 18.5C16.5 18.5 18.5 16.5 18.5 14C18.5 11.5 16.5 9.5 14 9.5Z</StreamGeometry>
<StreamGeometry x:Key="Icon.Search">M11 2A9 9 0 1 1 4.6 17.3L1 20.9L2.1 22L5.7 18.4A9 9 0 0 1 11 2Z</StreamGeometry>
</Application.Resources>
Use them with PathIcon:
<Button xmlns="https://github.com/avaloniaui">
<StackPanel Orientation="Horizontal" Spacing="8">
<PathIcon Width="16" Height="16" Data="{StaticResource Icon.Settings}" />
<TextBlock VerticalAlignment="Center" Text="Settings" />
</StackPanel>
</Button>
Centralize size and color with style:
<Style Selector="PathIcon.app-icon">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
</Style>
Usage:
<PathIcon Classes="app-icon" Data="{StaticResource Icon.Search}" />
When you need direct path drawing behavior instead of semantic icon behavior, use Shapes.Path.
using Avalonia.Controls;
using Avalonia.Media;
public static class AppIcons
{
public static readonly Geometry Search = Geometry.Parse("M11 2A9 9 0 1 1 4.6 17.3L1 20.9L2.1 22L5.7 18.4A9 9 0 0 1 11 2Z");
}
var icon = new PathIcon
{
Data = AppIcons.Search,
Width = 16,
Height = 16
};
Use code construction for generated icons or plugin-delivered path data.
PathIcon for icon semantics; use Shapes.Path for arbitrary vector layout.Foreground from theme resources so icons follow theme variants.Data is null or invalid path data.Foreground is transparent or same as background.Width/Height mismatch expected aspect ratio.Foreground.