Skip to main content

WindowsFormsSettings.PreferredDateTimeCulture Property

Gets or sets the culture settings used by date-time (calendar, scheduler, etc.) controls for month names, day abbreviations, and the first day of week.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.Utils.v24.1.dll

NuGet Packages: DevExpress.Utils, DevExpress.Wpf.Core

Declaration

public static DateTimeCulture PreferredDateTimeCulture { get; set; }

Property Value

Type Description
DevExpress.XtraEditors.DateTimeCulture

A DevExpress.XtraEditors.DateTimeCulture enumeration value, such as CurrentCulture and CurrentUICulture, that specifies the culture used by date-time controls.

Remarks

By default, .NET Framework applications use the system’s default culture for user interface. Typically, the same culture settings are used for date-time and currency formats, and calendar settings. However, an end-user can specify a custom culture for date-time formats and calendar settings, using the regional and language options of the Control Panel. See the figure below.

CurrentCultureSettings

In code, you can use the following per-thread static properties to get or set the current culture for the user interface and formatting:

  • Thread.CurrentThread.CurrentUICulture (see CurrentUICulture) - gets or sets the culture for the user interface;
  • Thread.CurrentThread.CurrentCulture (see CurrentCulture) - gets or sets the culture for date-time, currency formatting, calendar month names, day abbreviations, the first day of week, etc.

The code snippet below shows how to enable a custom culture for the UI and date-time formats.

// Set a culture for date-time formats. By default, this setting is fetched from the regional options of Control Panel.
Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
// Set a culture for the user interface. By default, this setting corresponds to the system's culture.
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");

Below, you can see the DateEdit that respects the specified settings.

CurrentCultureSettings_De

Note that button captions are translated into German based on localization assemblies. Month names, day abbreviations are also in German based on the specified culture information. Edit box date-time formatting is also set according to the German culture.

By default, when the PreferredDateTimeCulture property set to CurrentCulture, to display month names, day abbreviations, and the first day of week, DevExpress date-time controls use format settings specified with the Thread.CurrentThread.CurrentCulture property. This commonly used approach respects the end-user’s date-time format preferences, but may lead to inconsistency between the user interface language and the language used for month names and day abbreviations, since they are fetched from the culture information rather than from localization assemblies.

In the figure below, you can see the DateEdit that runs under Windows that uses German as the system’s language, while the end-user’s regional settings are set to English (United States).

CurrentCultureSettings_De_En

To force DevExpress date-time controls use the UI culture settings specified with the Thread.CurrentThread.CurrentUICulture property, set the PreferredDateTimeCulture property to CurrentUICulture. See the result below.

CurrentCultureSettings_De_Force

Note that setting the PreferredDateTimeCulture property to CurrentUICulture affects only the UI captions, while date-time formatting in edit boxes is still set in English (United States) culture.

See Also