WinUI.TableView icon indicating copy to clipboard operation
WinUI.TableView copied to clipboard

Derive default formats for dates and times from user profile language

Open VisualAlf opened this issue 10 months ago • 0 comments

... and not from app runtime language.

Running the new SampleApp I noticed the 'Dob' and the 'Active At' Columns have the US-Format (12Hour and MM/dd/yyyy). Instead in Germany it should be 24HourClock and Dateformat dd.MM.yyyy

Image

I believe the reason why this happens with the SampleApp but not with my own Apps, is the entry 'Default Language' within Package.appxmanifest. Which is set to 'en_US' in SampleApp, but to 'de-DE' within mine. So it seems, DateTimeFormatter selects the app runtime language.

Instead we should use the user profile language as defined in (win11) Settings > Time & Language > Region & language > Languages. Then the user will automatically see the date/time formats s/he is used to, and not the ones the developer of the app is used to use.

One way to achieve this is to change the default formats in TableViewTimeColumn and in TableViewDateColumn.

  • in TableViewTimeColumn.ctor from: ClockIdentifier = DateTimeFormatter.ShortTime.Clock; to: ClockIdentifier = GlobalizationPreferences.Clocks[0];

  • in TableViewDateColumn.ctor from: DateFormat = DateTimeFormatter.ShortDate.Patterns[0]; to: DateFormat = new DateTimeFormatter("shortdate", GlobalizationPreferences.Languages).Patterns[0];

VisualAlf avatar Feb 15 '25 09:02 VisualAlf