Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding the provider's static instance #27

Merged
merged 2 commits into from
Dec 9, 2023

Conversation

amywarble
Copy link
Contributor

This allows package consumers to override some icons by setting the data provider.

The provider instance cannot be null. Attempting to set the provider instance to null will throw an ArgumentNullException.

It can be used as:

public class CustomIconProvider : MaterialIconDataProvider
{
    public override string ProvideData(MaterialIconKind kind)
    {
        return kind switch
        {
            MaterialIconKind.TrophyVariant => "some SVG code",
            _ => base.ProvideData(kind)
        };
    }
}

internal static class Program
{
    public static int Main(string[] args)
    {
        MaterialIconDataProvider.Instance = new CustomIconProvider(); // use custom icons

        return BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
    }
}

@amywarble amywarble marked this pull request as draft December 9, 2023 02:04
@amywarble amywarble marked this pull request as ready for review December 9, 2023 02:07
@amywarble amywarble mentioned this pull request Dec 9, 2023
@SKProCH SKProCH merged commit 3c41c56 into SKProCH:master Dec 9, 2023
@amywarble amywarble deleted the set_singleton branch December 9, 2023 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants