I’ve created a DateTimePicker class with a bindable property DateTimeValue:
public class DateTimePicker : Grid
{
private readonly DatePicker datePicker;
private readonly TimePicker timePicker;
public static readonly BindableProperty DateTimeValueProperty = BindableProperty.Create(nameof(DateTimeValue), typeof(DateTime), typeof(DateTimePicker), defaultBindingMode: BindingMode.TwoWay, defaultValue: DateTime.Today);
public DateTime DateTimeValue
{
set
{
SetValue(DateTimeValueProperty, value);
datePicker.Date = value.Date;
timePicker.Time = value.TimeOfDay;
}
get => (DateTime)GetValue(DateTimeValueProperty);
}
...
}
I pass to a contentPage an instance of this class:
public class ActionDescriptor
{
public string Note { get; set; }
public DateTime Moment_1 { get; set; }
}
In this contentPage, I set then BindingContext in the constructor:
BindingContext = action;
action is of type ActionDescriptor.
In the XAML of this contentPage:
<tc:DateTimePicker DateTimeValue="{Binding Moment_1, Mode=TwoWay}" />
<Entry Text="{Binding Note, Mode=TwoWay}" />
The binding on the Entry works fine. The binding on the DateTimePicker does not work.