expressappframework-devexpress-dot-expressapp-dot-xafapplication-dot-setformattingculture-x28-system-dot-string-x29.md
Sets the specified formatting culture for the XAF WinForms application. To localize and change formatting culture for the XAF ASP.NET Core Blazor applications, refer to the following topics: Localize an XAF Application and IXafCultureInfoService.
Namespace : DevExpress.ExpressApp
Assembly : DevExpress.ExpressApp.v25.2.dll
NuGet Package : DevExpress.ExpressApp
public void SetFormattingCulture(
string formattingCultureName
)
Public Sub SetFormattingCulture(
formattingCultureName As String
)
| Name | Type | Description |
|---|---|---|
| formattingCultureName | String |
The name of the formatting culture that must be used in the application.
|
An XAF application uses the formatting culture that is set in the current user’s operating system or passed by the Internet browser (see Culture-Specific Formatting). You can set another formatting culture during the application’s runtime. For this purpose, use the SetFormattingCulture method. Internally, this method changes the Thread.CurrentCulture value. The simple example of using this method is provided in the Culture-Specific Formatting. The more complex example is detailed below.
This example demonstrates how to add the ChooseLanguage and ChooseFormattingCulture Actions that allow end-uses to switch between predefined languages and formatting cultures. Perform the following steps:
Main.SingleChoiceAction item from the Toolbox’ DX: XAF Actions page to the Controller’s Designer area. Set the Action’s Name and ID properties (here, ChooseLanguage), the Caption property (here, Choose Language) and the ActionBase.Category property (here, Tools).SingleChoiceAction item. Specify its properties correspondingly. Here, the Name and ID properties are set to ChooseFormattingCulture, and the Caption property is set to Choose Formatting Culture.XafApplication.SetFormattingCulture methods, respectively, passing the currently selected Action Item (see the code).using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using System.Globalization;
//...
public partial class ChangeLanguageController : WindowController {
public ChangeLanguageController() {
InitializeComponent();
}
private string defaultCulture;
private string defaultFormattingCulture;
private void ChangeLanguageController_Activated(object sender, EventArgs e) {
GetDefaultCulture
ChooseLanguage.Items.Add(new ChoiceActionItem(string.Format("Default ({0})",
defaultCulture), defaultCulture));
ChooseLanguage.Items.Add(new ChoiceActionItem("German (de)", "de"));
ChooseFormattingCulture.Items.Add(new ChoiceActionItem(string.Format(
"Default ({0})", defaultFormattingCulture), defaultFormattingCulture));
ChooseFormattingCulture.Items.Add(new ChoiceActionItem("German (de)", "de"));
}
private void GetDefaultCulture() {
defaultCulture = CultureInfo.InvariantCulture.TwoLetterISOLanguageName;
defaultFormattingCulture = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
}
private void ChooseLanguage_Execute(
object sender, SingleChoiceActionExecuteEventArgs e) {
Application.SetLanguage(e.SelectedChoiceActionItem.Data as string);
}
private void ChooseFormattingCulture_Execute(
object sender, SingleChoiceActionExecuteEventArgs e) {
Application.SetFormattingCulture(e.SelectedChoiceActionItem.Data as string);
}
}
See Also