Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions AsyncImageLoader.Avalonia/ImageBrushLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ private static async void OnSourceChanged(ImageBrush imageBrush, AvaloniaPropert
try {
if (!string.IsNullOrWhiteSpace(newValue)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we need to check on null there, since it checked to null in AdvancedImage, lets standardize that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that on line 31/32? AdvancedImage is an instance so its easier to check for null FallbackImage.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, the AdvancedImage has the same logic, i'm just dumb

bitmap = await AsyncImageLoader.ProvideImageAsync(newValue!);
} else {
var fallback = GetFallbackImage(imageBrush);
if (fallback != null) {
Comment thread
SKProCH marked this conversation as resolved.
Outdated
bitmap = fallback!;
imageBrush.Source = bitmap;
SetIsLoading(imageBrush, false);
return;
}
}
}
catch (Exception e) {
Expand All @@ -42,6 +50,17 @@ private static async void OnSourceChanged(ImageBrush imageBrush, AvaloniaPropert
public static readonly AttachedProperty<string?> SourceProperty =
AvaloniaProperty.RegisterAttached<ImageBrush, string?>("Source", typeof(ImageLoader));

public static readonly AttachedProperty<Bitmap?> FallbackImageProperty =
Comment thread
SKProCH marked this conversation as resolved.
Outdated
AvaloniaProperty.RegisterAttached<ImageBrush, Bitmap?>("FallbackImage", typeof(Bitmap));

public static Bitmap? GetFallbackImage(ImageBrush element) {
return element.GetValue(FallbackImageProperty);
}

public static void SetFallbackImage(ImageBrush element, Bitmap? value) {
element.SetValue(FallbackImageProperty, value);
}

public static string? GetSource(ImageBrush element) {
return element.GetValue(SourceProperty);
}
Expand Down