maui
maui copied to clipboard
Datepicker Two-Way Binding On Android
Description
I'm having an issue with DatePicker's behavior and am going to assume it is a bug.
Here is what our DatePicker looks like in XAML:
DateValue is a property that belongs to the CustomFormField model. A DateValue of null is an acceptable value within the CustomFormField. When the picker renders on screen, it displays today's date by default (when TextValue starts at null):
If you click on the DatePicker and attempt to select today's date, the DateSelected event is not fired therefore failing to bind to the new date. The only way to fire the DateSelected event is to select a different date on the DatePicker and then go back and select today's date.
(Since I am not testing on iOS, I cannot confirm if this is a bug on iOS)
Steps to Reproduce
- Create a DatePicker and bind the Date property to a null date property within a model.
- Create a function in the code behind file to be called when DateSelected event is fired.
- Use a breakpoint (or pop-up) in the code behind function.
- Select today's date with the DatePicker.
- Watch as the function in the code behind isn't called.
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12
Did you find any workaround?
My terrible and unacceptable workaround is setting model properties in the code behind.
Relevant log output
No response
I'm having the same issue (using Windows platform)... it seems like the Date
binding is not being observed by the control. I have tried OneWay
and TwoWay
to no avail. The only workaround I could find was to attach a EventToCommandBehavior
to the DateSelected
event.
Same problem using visual studio 2022 17.4.0 Preview 1.0 with MAUI. Setting the Datepickers Date to ViewModel observableProperty via Binding and changing the binding source value does not update to the Datepicker. Datepicker only shows todays date and Binding do not change it.
@samhouts Could you reconsider this item? Having the Date binding not work on Android is the mainline, most basic scenario for this control, which leaves it broken out of the box. It seems like it shouldn't be in the backlog.