GenericValueConverter.cs 622 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Globalization;
  3. using Avalonia.Data.Converters;
  4. #nullable enable
  5. namespace BindingDemo;
  6. public class GenericValueConverter<T> : IValueConverter
  7. {
  8. public GenericValueConverter()
  9. {
  10. }
  11. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  12. {
  13. if (value is T)
  14. {
  15. return $"{typeof(T).Name}: {value}";
  16. }
  17. return null;
  18. }
  19. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  20. {
  21. throw new NotSupportedException();
  22. }
  23. }