123456789101112131415161718192021222324252627282930 |
- using Avalonia.Data.Converters;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AvaloniaApplication2.Resources
- {
- internal class DateConverter : IValueConverter
- {
- // from VM to Viev
- public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
- {
- if (value is DateTime) return new DateTimeOffset((DateTime)value, TimeSpan.Zero);
- return null;
- }
- //from View to VM
- public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
- {
- if (value is DateTimeOffset myDateTimeOffset)
- {
- return new DateTime(myDateTimeOffset.Year, myDateTimeOffset.Month, myDateTimeOffset.Day);
- }
- return null;
- }
- }
- }
|