DateConverter.cs 812 B

123456789101112131415161718192021222324252627
  1. using Avalonia.Data.Converters;
  2. using System;
  3. using System.Globalization;
  4. namespace DatabaseMVVMApp.Converters
  5. {
  6. internal class DateConverter : IValueConverter
  7. {
  8. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  9. {
  10. if (value is DateTime)
  11. {
  12. return new DateTimeOffset((DateTime)value, TimeSpan.Zero);
  13. }
  14. return null;
  15. }
  16. public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  17. {
  18. if (value is DateTimeOffset myDateTimeOffset)
  19. {
  20. return new DateTime(myDateTimeOffset.Year, myDateTimeOffset.Month, myDateTimeOffset.Day);
  21. }
  22. return null;
  23. }
  24. }
  25. }