CrossGeeks / ClearableDatePickerSample

Clearable DatePicker Sample in Xamarin Forms
MIT License
19 stars 11 forks source link

initial date binding does not display #8

Open Roller007 opened 6 years ago

Roller007 commented 6 years ago

Xamarin Forms: 2.5.0.28

If there is a date when initially coming to the page the control will not show the date even though a date is bound to the control.

I can choose a new date and save, or even save with the initially bound date, that works fine but it will not show the initially bound date.

XamDevToo commented 5 years ago

Same here Xamarin Forms: 3.4.0.1029999, difficult to fix,

For example in Android NulleableDatePickerRenderer class, OnElementPropertyChanged method (M#1) never receive a PropertyName value "NulleableDate" and OnElementChange method (M#2 who set the bound value) is called before M#1 making impossible to set the bound value IF were received in M#1.

The binding property used is NulleableDate, the DateTimeToStringConverter (IValueConverter) Convert method (M#3) receive null as binding value for every NullableDatePicker control of the xaml page and is called before M#1 and M#2 methods, this is the control declaration:

<customControls:NullableDatePicker MaximumDate="{x:Static system:DateTime.Today}" NullableDate="{Binding PersonaModel.per_fecha_nacimiento, Converter={StaticResource DateTimeToStringConverter}}" Format="{StaticResource FormatoFecha}"/>

Very nice solution but useless without binding, any suggestions to fix this problem?

bsmarshall commented 4 years ago

@XamDevToo I had the same issue and after quite a bit of debugging I found that my bound field was a DateTimeOffset. I corrected my converter to properly pass in a DateTime and it worked. In your example your converter is converting between DateTime and String. Perhaps you need to review your converter too.

No doubt you've moved on from this but this may assist someone else in the future.