ceastgun
ceastgun

Reputation: 91

I want to change the DatePicker Style of UWP

I want to change the DatePicker Style of UWP as shown below.

I want year to come first and month to come second.

I modified the style but it does not work.

What should I do?

Thank you for your reply.

enter image description here

Upvotes: 0

Views: 766

Answers (1)

Sunteen Wu
Sunteen Wu

Reputation: 10627

According to this article:

There are many different ways to properly display dates and times. Different regions and cultures use different conventions for the order of day and month in the date, for the separation of hours and minutes in the time, and even for what punctuation is used as a separator.

If you use date and time picker controls, these will automatically use the date and time formats for the user's preferred language and region. So the order is defined by the user's preferred language and region that you should not be able to change them by the style of DatePicker.

The first image you showed above seems like preferred language is en-US and home region is US. For scenarios where you provide different functionality based on the user's language, region, or cultural preferences, Windows gives you a way to access those preferences, through Windows.System.UserProfile.GlobalizationPreferences. And the second image seems like preferred language is Chinese. The preferred language can be override by property PrimaryLanguageOverride. Pay attention that the PrimaryLanguageOverride property should only be set to languages that are available for the user.

So if you change the prefer language to Chinese the DataPicker may be shown in order year-mouth-day. Also formats need be changed as the second image show. Code as follows:

<DatePicker  BorderThickness="0" FontFamily="Arial Black" FontSize="15" FontWeight="Bold"  MinWidth="190" DayFormat="{}{day.integer(2)}" MonthFormat="month.numeric" YearFormat="{}{year.full(4)}"   />

Code behind

  ApplicationLanguages.PrimaryLanguageOverride = "zh-Hans-CN";

And the result

enter image description here

To respect the user's Language and Cultural Preferences, this may not be recommended to change.

Upvotes: 1

Related Questions