XAML SVG Icons

By the Axialis Engineering team ·

XAML SVG Icons

Bitmap icons can blur when scaled and may need alternate colors for light and dark themes. For WPF and WinUI, an alternative is to ship icons as XAML Path geometry: scalable vector data whose colors can follow your app's brushes and theme resources. This guide exports that geometry from IconVectors and wires it into your app — binding Fill and Foreground to brushes, naming actionable controls with AutomationProperties.Name, and packaging the paths as a reusable ResourceDictionary.

When to choose XAML code

Draw, Import or Trace your icon

The IconVectors editor with a heart icon drawn on a 24-pixel grid, ready to export as XAML Path geometry

Export XAML from IconVectors

  1. Design on a consistent grid (e.g. 24×24). Keep strokes aligned to whole pixels so the geometry snaps cleanly at 100% scale.
  2. Decide your theming strategy. For single-color icons, bind Fill or Stroke to a brush rather than baking in a hex value — that is what lets the icon follow the theme (see below).
  3. Open View → Source Code (F3) and switch to the XAML tab to see the generated Path markup.
  4. Copy the geometry string or the full Path and paste it into your app as shown next.

WPF: simple Path bound to Foreground

This WPF example gives the button one content container, holding both the icon and its visible label. The decorative path has no separate accessible name. Use it within a WPF window or page with the standard presentation and x: namespaces.

<Grid>
  <Grid.Resources>
    <Style x:Key="IconPathStyle" TargetType="Path">
      <Setter Property="Stretch" Value="Uniform"/>
      <Setter Property="Fill" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"/>
      <Setter Property="SnapsToDevicePixels" Value="True"/>
    </Style>
  </Grid.Resources>

  <Button Padding="8" AutomationProperties.Name="Favorite">
    <StackPanel Orientation="Horizontal">
      <Path Style="{StaticResource IconPathStyle}"
            Width="24" Height="24" Focusable="False"
            Data="M2.5 9C2.5 2.5 10 3 12 7.5C14 3 21.5 2.5 21.5 9C21.5 15.4 12 21.5 12 21.5C12 21.5 2.5 15.6 2.5 9z"/>
      <TextBlock Text="Favorite" Margin="8,0,0,0"
                 VerticalAlignment="Center"/>
    </StackPanel>
  </Button>
</Grid>

RelativeSource finds the containing Button and tracks its Foreground. This is WPF syntax. It does not automatically track brushes applied only inside a control template; test hover, pressed, focused, and disabled states with your actual style.

WPF: package as a reusable resource (Geometry)

Place these entries in your WPF window or application resources, or merge this dictionary into them, before using the path below. Share the Geometry, and create a separate Path for each use.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <SolidColorBrush x:Key="IconBrush" Color="#2563EB"/>
  <Geometry x:Key="Heart24Geometry">M2.5 9C2.5 2.5 10 3 12 7.5C14 3 21.5 2.5 21.5 9C21.5 15.4 12 21.5 12 21.5C12 21.5 2.5 15.6 2.5 9z</Geometry>
</ResourceDictionary>
<Path Data="{StaticResource Heart24Geometry}"
      Width="24" Height="24"
      Stretch="Uniform"
      Fill="{DynamicResource IconBrush}"
      Focusable="False"/>

IconBrush is an illustrative fixed color, not an automatically changing theme palette. WPF DynamicResource reevaluates the reference when the resource changes; your app must provide the appropriate brush for each theme and background. This path is decorative; expose any required meaning through its containing control or an accessible text equivalent.

WinUI 3: PathIcon with a theme brush

In a WinUI 3 page, use Microsoft.UI.Xaml controls and ThemeResource, not WPF DynamicResource or FindAncestor bindings. This command button exposes one accessible name; its icon is decorative.

<AppBarButton Label="Favorite"
              AutomationProperties.Name="Favorite"
              Foreground="{ThemeResource TextFillColorPrimaryBrush}">
  <AppBarButton.Icon>
    <PathIcon Data="M2.5 9C2.5 2.5 10 3 12 7.5C14 3 21.5 2.5 21.5 9C21.5 15.4 12 21.5 12 21.5C12 21.5 2.5 15.6 2.5 9z"
              AutomationProperties.AccessibilityView="Raw"/>
  </AppBarButton.Icon>
</AppBarButton>

TextFillColorPrimaryBrush is a WinUI theme resource with light, dark, and high-contrast definitions. The AppBarButton foreground above applies to its default state; its template supplies other state brushes. Leaving PathIcon.Foreground unset avoids pinning the icon to one brush across all states. Wire the button to your app's command or click handler, and check contrast against the actual background in every applicable state.

Accessibility checklist

Theming options (brushes & bindings)

Performance & packaging tips

Reference example (WPF Path)

This decorative WPF path uses the IconBrush resource defined above. Its containing control or accompanying text must provide any accessible meaning.

<Path Width="24" Height="24" Stretch="Uniform"
      StrokeThickness="1" StrokeLineJoin="Round" StrokeStartLineCap="Round" StrokeEndLineCap="Round"
      Data="M2.5 9C2.5 2.5 10 3 12 7.5C14 3 21.5 2.5 21.5 9C21.5 15.4 12 21.5 12 21.5C12 21.5 2.5 15.6 2.5 9z"
      Fill="{DynamicResource IconBrush}"
      Focusable="False"/>

Related guides

Start Making SVG Icons Today with IconVectors

Download the fully-functional 30‑Day Free Trial and unlock your icon design workflow.

IconVectors 2.20 for Windows, macOS and Linux.