I am using a CalendarDatePicker control in UWP. The format of the date should be localized to the user's chosen culture, which is not necessarily the same as the OS language settings. I want the date format to appear the same as myCultureInfo.DateTimeFormat.ShortDatePattern (e.g. mm/dd/yyyy). The CalendarDatePicker exposes a DateFormat property which is expected to be in a format like {month.integer}/{day.integer}/{year.full}. I need a converter for the XAML binding. It seems like there should be a simple way to do this.
<!-- In XAML -->
<CalendarDatePicker
FirstDayOfWeek="{x:Bind ViewModel.CalendarFirstDayOfWeek, Mode=OneTime, Converter={StaticResource SystemDayOfWeekToWindowsDayOfWeekConverter}}"
DateFormat="{x:Bind ViewModel.DateFormat, Mode=OneWay, Converter={StaticResource DateTimeFormatToDateTimeFormatterTemplateConverter}"
Date="{x:Bind ViewModel.Date, Mode=TwoWay, Converter={StaticResource DateTimeToDateTimeOffsetConverter}}"/>
//Converter
public class DateTimeFormatToDateTimeFormatterTemplateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
//What goes here?
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Edit: Ideally the CalendarDatePicker would just have a CultureInfo property that would take care of all of this. I tried the Language property but it had no noticeable effect.