Schlauchliner erweitert
This commit is contained in:
31
DaSaSo.Wpf/Converters/StringToDateTimeConverter.cs
Normal file
31
DaSaSo.Wpf/Converters/StringToDateTimeConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DaSaSo.Wpf.Converters
|
||||
{
|
||||
[ValueConversion(typeof(DateTime), typeof(String))]
|
||||
public class StringToDateTimeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
DateTime val = (DateTime)value;
|
||||
return string.Format("{0}.{1}.{2} {3}:{4}",val.Day,val.Month, val.Year, val.Hour, val.Minute);
|
||||
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
DateTime result;
|
||||
if (DateTime.TryParse((value as string), out result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user