Projektanker.Icons.Avalonia 3.2.0

There is a newer version of this package available.
See the version list below for details.
Install-Package Projektanker.Icons.Avalonia -Version 3.2.0
dotnet add package Projektanker.Icons.Avalonia --version 3.2.0
<PackageReference Include="Projektanker.Icons.Avalonia" Version="3.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Projektanker.Icons.Avalonia --version 3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Projektanker.Icons.Avalonia, 3.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Projektanker.Icons.Avalonia as a Cake Addin
#addin nuget:?package=Projektanker.Icons.Avalonia&version=3.2.0

// Install Projektanker.Icons.Avalonia as a Cake Tool
#tool nuget:?package=Projektanker.Icons.Avalonia&version=3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Icons.Avalonia

A library to easily display icons in an Avalonia App.

CI-CD

NuGet

Name Description Version
Projektanker.Icons.Avalonia Core library Nuget
Projektanker.Icons.Avalonia.FontAwesome Font Awesome Free Nuget
Projektanker.Icons.Avalonia.MaterialDesign Material Design Icons Nuget

Icon providers

Name Prefix Example
FontAwesome fa fa-github
MaterialDesign mdi mdi-github

Usage

A full example is available in the demo directory.

1. Register icon providers on app start up

Use the AppBuilder.AfterSetup method to register a callback. Within this callback register the icon prodider(s). Otherwise the visual designer won't be able to use the registered icon provider(s).

class Program
{
    // Initialization code. Don't use any Avalonia, third-party APIs or any
    // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
    // yet and stuff might break.
    public static void Main(string[] args)
    {
        BuildAvaloniaApp()
            .StartWithClassicDesktopLifetime(args);
    }

    // Avalonia configuration, don't remove; also used by visual designer.
    public static AppBuilder BuildAvaloniaApp()
    {
        return AppBuilder.Configure<App>()
            .AfterSetup(AfterSetupCallback)
            .UsePlatformDetect()
            .LogToTrace();
    }
    
    // Called after setup
    private static void AfterSetupCallback(AppBuilder appBuilder)
    {
        // Register icon provider(s)
        IconProvider.Register<FontAwesomeIconProvider>();
        IconProvider.Register<MaterialDesignIconProvider>();
    }
}

2. Add xml namespace

Add xmlns:i="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia" to your view.

3. Use the icon

Example: The GitHub icon.
FontAwesome

<i class="fab fa-github"></i>

Standalone

<i:Icon Value="fab fa-github" />

Attached

<Button i:Attached.Icon="fab fa-github" />

Done

Screenshot
Screenshot

Implement your own Icon Provider

Just implement the IIconProvider interface:

namespace Projektanker.Icons.Avalonia
{
    /// <summary>
    /// Represents an icon provider.
    /// </summary>
    public interface IIconProvider
    {
        /// <summary>
        /// Gets the prefix of the <see cref="IIconProvider"/>.
        /// </summary>
        string Prefix { get; }

        /// <summary>
        /// Gets the SVG path of the requested icon using the registered icon providers.
        /// </summary>
        /// <param name="value">The value specifying the icon to return it's path from.</param>
        /// <returns>The path of the icon.</returns>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">The icon associated
        /// with the specified <paramref name="value"/> does not exists.</exception>
        string GetIconPath(string value);
    }
}

and register it with the IconProvider:

IconProvider.Register<MyCustomIconProvider>()

or

IIconProvider provider = new MyCustomIconProvider(/* custom ctor arguments */);
IconProvider.Register(provider);

The IIconProvider.Prefix property have to be unique within all registered providers. It is used to select the right provider. E.g. FontAwesomeIconProvider's prefix is fa.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Projektanker.Icons.Avalonia:

Package Downloads
Projektanker.Icons.Avalonia.FontAwesome

A library to easily display FontAwesome icons in an Avalonia App.

Projektanker.Icons.Avalonia.MaterialDesign

A library to easily display Material Design icons in an Avalonia App.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.7.0 970 11/20/2021
3.5.0 189 11/12/2021
3.4.1 273 11/8/2021
3.4.0 234 11/8/2021
3.2.0 458 10/17/2021
3.1.4 233 10/14/2021
3.1.2 1,325 8/13/2021
3.1.1 225 8/11/2021
3.1.0 976 3/22/2021
3.1.0-pre 143 3/22/2021
3.0.0 647 10/29/2020
3.0.0-pre 344 10/29/2020
2.0.2 362 8/12/2020
2.0.1 342 7/27/2020
2.0.0 313 7/27/2020
1.0.0 238 7/27/2020