Description
I want to use the SfDatePicker to allow the user to choose a date. I use a custom date format (dd-MM-yyyy) to have it match the Dutch date format.
However, after binding this control to a DateTime value (I used the date: September 4, 2021), the SfDatePicker shows the day and month swapped.
Is there a way to have the SfDatePicker work with such custom date format?
Steps to reproduce
Configuration
Xamarin.Forms v5.0.0.2012
Syncfusion.Xamarin.SfPicker v18.3.0.50 (also tested it with the latest version)
I added the reproduction project as an attachment.
Attachment: XamarinSfDatePicker_824bef72.zip
| public class DatetimeToStringConverter : IValueConverter
{
#region IValueConverter implementation
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return string.Empty;
var datetime = (DateTime)value;
var text = string.Format("{0:dd-MM-yyyy}", datetime);
return text;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return DateTime.Now;
CultureInfo provider = CultureInfo.InvariantCulture;
var dd = value.ToString();
DateTime dateTime = DateTime.ParseExact(dd,"dd-MM-yyyy", provider);
return dateTime;
}
#endregion } |
| <ResourceDictionary>
<local:DatetimeToStringConverter x:Key="cnvDateTimeConverter"></local:DatetimeToStringConverter> </ResourceDictionary>... <Entry Text="{Binding StartDate,Converter={StaticResource cnvDateTimeConverter}}" x:Name="entry" IsReadOnly="True" InputTransparent="False"/> ... |
That was indeed the solution, thank you!