xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

DatePicker.Format doesn't work on UWP platform . #8670

Open luczha opened 4 years ago

luczha commented 4 years ago

I have a DatePicker in my application and I want to display the date in this format : 11/26/2019 So I change the Format property as follow :

myDatePicker.Format = "MM/dd/yyyy"
myDatePicker.Date = DateTime.Now;

Above code works fine on Android and iOS , but on UWP ,the display date got this format : November 26 2019 .

WayaFlyfeather commented 4 years ago

I can confirm that the DatePicker uses a UWP DatePicker, and apparently always uses the default format:

2019-11-26

The formatting options for the UWP DatePicker are limited (AFAICT you can't change the order of the the month, day, year), this is determined by the current locale, I believe. Perhaps that's why formatting seems to have been skipped. But it is possible to set the format of the individual items - if month should be shown by name (November) or number (11), for example.

I'd like to look into implementing the parts of the format that could be used in a UWP DatePicker, if desired. I could imagine, though, that it is a change that may bring some layout surprises for those who currently use a format on iOS/Android, but are used to it being the UWP default on UWP.

luczha commented 4 years ago

I had provided customer a workaround https://stackoverflow.com/questions/59049375/change-datepicker-month-format-in-xamarin

jfversluis commented 4 years ago

Looks like the Format has no effect on UWP indeed. Looking at the code this might never have been implemented to begin with.

Repro8670.zip

Only-Xam commented 3 years ago

Also, DatePicker and TimePicker are using default width on UWP. WidthRequest and/or MinimumWidthRequest are not making any difference.

Also, even if you use StateTriggers to reduce size by setting ScaleX when window is narrow, size of DatePicker/TimePicker reduces but actual width used by these two controls still remain same, so in short, you wont see any difference.

XF 5.0.01709.pre4

<DatePicker x:Name="MyDatePicker" WidthRequest="300" MinimumWidthRequest="250"/>

No difference even if we put it inside the StackLayout.

`

`

Here during narrow window, ScaleX is set to 0.8 which visually reduced the size but actual width taken by these control still remain same even if Spacing is set to 0. You can see when window is narrow control is not fittin in the screen.

image