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: 26 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: 2024-11-11T23:47:32.000Z (about 1 month ago)
- Last Synced: 2024-11-12T03:40:24.334Z (about 1 month ago)
- Topics: avaloniaui, fontawesome6, icons, materialdesignicons
- Language: C#
- Homepage:
- Size: 10.4 MB
- Stars: 305
- Watchers: 5
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-avalonia - Icons.Avalonia - A library to easily display icons in an Avalonia App. (Libraries & Extensions / Theme & Icons)
README
# Icons.Avalonia
A library to easily display icons in an Avalonia App.
[![🚀 Push](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/push.yml/badge.svg)](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/push.yml)
[![🔄 Sync Fontawesome](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/sync-fontawesome.yml/badge.svg)](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/sync-fontawesome.yml)
[![🔄 Sync Material Design](https://github.com/Projektanker/Icons.Avalonia/actions/workflows/sync-materialdesign.yml/badge.svg)](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 | ![Nuget](https://badgen.net/nuget/v/Projektanker.Icons.Avalonia) |
| [Projektanker.Icons.Avalonia.FontAwesome](https://www.nuget.org/packages/Projektanker.Icons.Avalonia.FontAwesome/) | [Font Awesome 6 Free](https://fontawesome.com) | ![Nuget](https://badgen.net/nuget/v/Projektanker.Icons.Avalonia.FontAwesome) |
| [Projektanker.Icons.Avalonia.MaterialDesign](https://www.nuget.org/packages/Projektanker.Icons.Avalonia.MaterialDesign/) | [Material Design Icons](https://pictogrammers.com/library/mdi/) | ![Nuget](https://badgen.net/nuget/v/Projektanker.Icons.Avalonia.MaterialDesign) |## 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
![Screenshot](/resources/demo.png?raw=true)
## 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`.