using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media.Imaging;
using XFEExtension.NetCore.StringExtension;
namespace XFEExtension.NetCore.WinUIHelper.Utilities.Converter;
///
/// Converts a URL string into a for use in UI elements.
///
/// This converter takes a string representing a URL and attempts to create a
/// from it. If the URL is null, empty, or consists only of whitespace, the method returns .
public partial class URLImageConverter : IValueConverter
{
///
/// Converts a string URL into a instance, or returns if the URL is
/// invalid or empty.
///
/// The input value to convert. Must be a string representing a URL.
/// The type to convert to. This parameter is not used in the conversion process.
/// An optional parameter for the conversion. This parameter is not used in the conversion process.
/// The language information for the conversion. This parameter is not used in the conversion process.
/// A created from the provided URL if the input is a non-empty string; otherwise, .
public object? Convert(object value, Type targetType, object parameter, string language) => value is string url ? !url.IsNullOrWhiteSpace() ? new BitmapImage(new(url)) : null : null;
///
/// Converts a value back to its original type or representation.
///
/// The value to be converted back. This is typically the result of a previous conversion.
/// The type to which the value should be converted. This parameter specifies the desired target type.
/// An optional parameter to use during the conversion. This can be used to provide additional context or
/// configuration.
/// The language or culture information to use during the conversion. This parameter may influence localization or
/// formatting.
/// An object representing the converted value. The default implementation returns an empty string.
public object ConvertBack(object value, Type targetType, object parameter, string language) => string.Empty;
}