|
@@ -1,6 +1,7 @@
|
|
|
using System.Globalization;
|
|
|
using System.Reflection;
|
|
|
using Avalonia;
|
|
|
+using Avalonia.Data;
|
|
|
using Avalonia.Media.Imaging;
|
|
|
using Avalonia.Platform;
|
|
|
|
|
@@ -10,11 +11,13 @@ internal class ImagePathToBitmapConverter : SingleInstanceConverter<ImagePathToB
|
|
|
{
|
|
|
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
{
|
|
|
- if (value is string path)
|
|
|
- {
|
|
|
- return new Bitmap(AssetLoader.Open(new Uri($"avares://{Assembly.GetExecutingAssembly().FullName}{path}")));
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
+ if (value is not string path)
|
|
|
+ return AvaloniaProperty.UnsetValue;
|
|
|
+
|
|
|
+ Uri uri = new($"avares://{Assembly.GetExecutingAssembly().FullName}{path}");
|
|
|
+ if (!AssetLoader.Exists(uri))
|
|
|
+ return AvaloniaProperty.UnsetValue;
|
|
|
+
|
|
|
+ return new Bitmap(AssetLoader.Open(uri));
|
|
|
}
|
|
|
}
|