You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
namespace Connected;
|
|
|
|
/// <summary>
|
|
/// A ready made DateTime? to string binding converter with configurable date format and culture
|
|
/// </summary>
|
|
public class NullableDateConverter : ToStringConverter<DateTime?>
|
|
{
|
|
public string DateFormat { get; set; }
|
|
|
|
public NullableDateConverter(string format = "yyyy-MM-dd") => DateFormat = format;
|
|
|
|
protected override string? ConvertValue(DateTime? value) => value?.ToString(DateFormat, Culture);
|
|
|
|
protected override DateTime? ConvertValueBack(string? value) => DateTime.ParseExact(value, DateFormat, Culture);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A ready made DateTime to string binding converter with configurable date format and culture
|
|
/// </summary>
|
|
public class DateConverter : ToStringConverter<DateTime>
|
|
{
|
|
public string DateFormat { get; set; }
|
|
|
|
public DateConverter(string format = "yyyy-MM-dd") => DateFormat = format;
|
|
|
|
protected override string? ConvertValue(DateTime value) => value.ToString(DateFormat, Culture);
|
|
|
|
protected override DateTime ConvertValueBack(string? value) => DateTime.ParseExact(value, DateFormat, Culture);
|
|
} |