34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace UniperHMI
|
|
{
|
|
public class DateTimeToEventTimeConverter : IValueConverter
|
|
{
|
|
// 599264352000000000 ticks is a date used by beckhoff for events that didnt happen up to this point
|
|
public const long NoTime = 599264352000000000;
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is DateTime dt)
|
|
{
|
|
|
|
if (dt.Ticks == NoTime)
|
|
return "";
|
|
else
|
|
{
|
|
CultureInfo cultureInfo = CultureInfo.CurrentCulture;
|
|
return dt.ToString("G", cultureInfo);
|
|
}
|
|
}
|
|
else
|
|
throw new InvalidOperationException("Target must be of type DateTime");
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return DependencyProperty.UnsetValue;
|
|
}
|
|
}
|
|
}
|