Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caliburn.Micro Binding DateTimeOffset to DatePicker

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?

like image 216
Rahul Avatar asked Aug 12 '15 15:08

Rahul


1 Answers

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/

like image 160
Telos Avatar answered Sep 28 '22 22:09

Telos