Catalog/imagecatalog/Converters/FilePathToBitmapConverter.cs

31 lines
728 B
C#
Raw Normal View History

using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
namespace ImageCatalog_2.Converters;
public sealed class FilePathToBitmapConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not string path || string.IsNullOrWhiteSpace(path))
{
return null;
}
try
{
return new Bitmap(path);
}
catch
{
return null;
}
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}