Skip to content

Added FallbackImage property#36

Merged
SKProCH merged 2 commits intoAvaloniaUtils:masterfrom
thewoodknight:master
Feb 1, 2026
Merged

Added FallbackImage property#36
SKProCH merged 2 commits intoAvaloniaUtils:masterfrom
thewoodknight:master

Conversation

@thewoodknight
Copy link
Contributor

This PR lets you set a fallback bitmap for if an image binding is set to null. Using a Bitmap means its a bit easier to cache in memory rather than every failure creating a new Bitmap

I may very well have missed how to do this with the library already, so my apologies if its already there.

Usage

<asyncImageLoader:AdvancedImage
		Loader="{x:Static app:App.ImageLoaderInstance}"
		FallbackImage="{x:Static app:App.FallbackImage}"
		Source="{Binding Path=., Converter={StaticResource MetadataImageConverter}}" />
private static Bitmap fallbackImage;
public static Bitmap FallbackImage
{
    get
    {
        return fallbackImage ??= new Bitmap(AssetLoader.Open(new Uri("avares://WateryTart.Core/Assets/cover_dark.png")));
    }
}

FallbackBinding on Source only triggers when the binding itself fails, rather than returning empty/null strings.

@SKProCH SKProCH merged commit 567b5ff into AvaloniaUtils:master Feb 1, 2026
@SKProCH
Copy link
Member

SKProCH commented Feb 1, 2026

Thanks!

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.

2 participants