DateConverter.cs 897 B

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