Replies: 2 comments
-
the culture is changed but that change doesn't make the UI to update.
and this causes the visible text to be regenerated but it's not needed to have culture depenent format since it's already is. 2024-11-01.17-25-41.mp4As you can see changing the date and forcing the text to be regenerated causes expected result. |
Beta Was this translation helpful? Give feedback.
-
Since you have Culture in your view model, instead of the CommunityToolkit.Mvvm [ObservableProperty] you could give it the following getter/setter: public CultureInfo Culture
{
get => CultureInfo.CurrentUICulture;
set
{
CultureInfo.CurrentCulture = value;
CultureInfo.CurrentUICulture = value;
OnPropertyChanged();
}
} This change will mean that if you set Culture it will set both CultureInfo.CurrentUICulture and CultureInfo.CurrentCulture directly but, more importantly, it will also raise OnPropertyChanged(). This is useful because we can now bind to it and get direct notification changes to a time and date formats: <DatePicker Format="{Binding Culture.DateTimeFormat.LongDatePattern}" />
<TimePicker Format="{Binding Culture.DateTimeFormat.LongTimePattern}" /> See pull request mijenner/MAUIappsFeatures#1 |
Beta Was this translation helpful? Give feedback.
-
As the title says, DatePicker and TimePicker doesn't currently use culture settings.
This means that non-US users would have to go and add Formats for DatePicker and TimePicker like:
Would it be possible for these UI elements to automatically use culture?
This is already done when using
<Label>
for displaying floating point numbers. Here culture is respected and enables using either "," or "." as decimal separator.Here is a simple project which toogles CultureInfo.CurrentCultureInfo and data-format and time-format strings to display the issue and see that ToString() uses culture: https://github.com/mijenner/MAUIappsFeatures .
Keep up the GREAT work!
Kind regards,
Michael
Beta Was this translation helpful? Give feedback.
All reactions