我想更改 UWP 的 DatePicker 样式

I want to change the DatePicker Style of UWP

我想更改 UWP 的 DatePicker 样式,如下所示。

我要年在前,月在后。

我修改了样式,但是没有用。

我该怎么办?

感谢您的回复。

根据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.

如果您使用 date and time picker 控件,这些控件将自动使用用户首选语言和地区的日期和时间格式。所以顺序是由用户的首选语言和地区定义的,你不应该能够通过 DatePicker 的样式来改变它们。

您在上面显示的第一张图片似乎首选语言是 en-US,家乡地区是 US。对于您根据用户的语言、地区或文化偏好提供不同功能的场景,Windows 为您提供了一种通过 Windows.System.UserProfile.GlobalizationPreferences. And the second image seems like preferred language is Chinese. The preferred language can be override by property PrimaryLanguageOverride 访问这些偏好的方法。请注意 PrimaryLanguageOverride 属性 应仅设置为用户可用的语言。

因此,如果您将首选语言更改为中文,DataPicker 可能会按 year-mouth-day 顺序显示。还需要更改格式作为第二个图像显示。代码如下:

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

代码隐藏

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

结果

为了尊重用户的语言和文化偏好,不建议更改。