I need to bind DateTimeOffset
property to a WPF DatePicker since Odata not supports DateTime
.
I know how to bind DateTime
property.
I have tried binding DateTimeOffset
property to DatePicker as same as binding DateTime
property.
But the value is not changing at all. It's always has the default value.
How can I solve this problem?
Try using this value converter.
public class DateTimeToDateTimeOffsetConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTimeOffset dto = (DateTimeOffset)value;
return dto.DateTime;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime date = (DateTime)value;
return new DateTimeOffset(date);
}
}
I based this solution on: http://bretstateham.com/binding-to-the-new-xaml-datepicker-and-timepicker-controls-to-the-same-datetime-value/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With