diff --git a/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs b/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs
index 8a1f032593..0d446d0729 100644
--- a/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs
+++ b/src/Avalonia.Base/Data/Converters/FuncValueConverter.cs
@@ -5,7 +5,7 @@ using Avalonia.Utilities;
namespace Avalonia.Data.Converters
{
///
- /// A general purpose that uses a
+ /// A general purpose that uses a
/// to provide the converter logic.
///
/// The input type.
@@ -42,4 +42,44 @@ namespace Avalonia.Data.Converters
throw new NotImplementedException();
}
}
+
+ ///
+ /// A general purpose that uses a
+ /// to provide the converter logic.
+ ///
+ /// The input type.
+ /// The param type.
+ /// The output type.
+ public class FuncValueConverter : IValueConverter
+ {
+ private readonly Func _convert;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The convert function.
+ public FuncValueConverter(Func convert)
+ {
+ _convert = convert;
+ }
+
+ ///
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (TypeUtilities.CanCast(value) && TypeUtilities.CanCast(parameter))
+ {
+ return _convert((TIn?)value, (TParam?)parameter);
+ }
+ else
+ {
+ return AvaloniaProperty.UnsetValue;
+ }
+ }
+
+ ///
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
}
diff --git a/src/Avalonia.Base/Data/Converters/ObjectConverters.cs b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs
index 6796a1793e..8496ee1ae6 100644
--- a/src/Avalonia.Base/Data/Converters/ObjectConverters.cs
+++ b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs
@@ -16,5 +16,17 @@ namespace Avalonia.Data.Converters
///
public static readonly IValueConverter IsNotNull =
new FuncValueConverter