Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/projektanker/icons.avalonia
https://github.com/projektanker/icons.avalonia
avaloniaui fontawesome6 icons materialdesignicons
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/projektanker/icons.avalonia
- Owner: Projektanker
- License: mit
- Created: 2020-07-15T17:31:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-11T06:22:48.000Z (10 days ago)
- Last Synced: 2025-02-17T02:02:29.989Z (4 days ago)
- Topics: avaloniaui, fontawesome6, icons, materialdesignicons
- Language: C#
- Homepage:
- Size: 10.3 MB
- Stars: 338
- Watchers: 5
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Icons.Avalonia
A library to easily display icons in an Avalonia App.
[](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/push.yml)
[](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/sync-fontawesome.yml)
[](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/sync-materialdesign.yml)## NuGet
| Name | Description | Version |
| :----------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :------------------------------------------------------------------------------ |
| [Projektanker.Icons.Avalonia](https://www.nuget.org/packages/Projektanker.Icons.Avalonia/) | Core library |  |
| [Projektanker.Icons.Avalonia.FontAwesome](https://www.nuget.org/packages/Projektanker.Icons.Avalonia.FontAwesome/) | [Font Awesome 6 Free](https://fontawesome.com) |  |
| [Projektanker.Icons.Avalonia.MaterialDesign](https://www.nuget.org/packages/Projektanker.Icons.Avalonia.MaterialDesign/) | [Material Design Icons](https://pictogrammers.com/library/mdi/) |  |## Icon providers
| Name | Prefix | Example |
| :------------- | :----: | :----------- |
| FontAwesome 6 | `fa` | `fa-github` |
| MaterialDesign | `mdi` | `mdi-github` |## Usage
A full example is available in the [Demo project](src/Demo/Demo.csproj).
### 1. Register icon providers on app start up
Register the icon provider(s) with the `IconProvider.Current`.
```csharp
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()
{
IconProvider.Current
.Register()
.Register();return AppBuilder.Configure()
.UsePlatformDetect()
.LogToTrace();
}
}
```### 2. Add xml namespace
Add `xmlns:i="https://github.com/projektanker/icons.avalonia"` to your view.
### 3. Use the icon
**Standalone**
```xml
```
**Attached to ContentControl (e.g. Button)**
```xml
```
**Attached to MenuItem**
```xml
```
**Custom icon size**
```xml
```
**Animated**
```xml
```
**As an [Image](https://docs.avaloniaui.net/docs/reference/controls/image) source**
```xml
```
### Done

## Implement your own Icon Provider
Just implement the `IIconProvider` interface:
```csharp
namespace Projektanker.Icons.Avalonia
{
///
/// Represents an icon reader.
///
public interface IIconReader
{
///
/// Gets the model of the requested icon.
///
/// The value specifying the icon to return it's model from.
/// The model of the icon.
///
/// The icon associated with the specified does not exists.
///
IconModel GetIcon(string value);
}///
/// Represents an icon provider.
///
public interface IIconProvider : IIconReader
{
///
/// Gets the prefix of the .
///
string Prefix { get; }
}
}
```and register it with the `IIconProviderContainer`:
```csharp
IconProvider.Current.Register()
```or
```csharp
IIconProvider provider = new MyCustomIconProvider(/* custom ctor arguments */);
IconProvider.Current.Register(provider);
```The `IIconProvider.Prefix` property has to be unique within all registered providers. It is used to select the right provider. E.g. `FontAwesomeIconProvider`'s prefix is `fa`.