XafApplication.SetFormattingCulture(String) Method
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.v26.1.dll
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| formattingCultureName | String | The name of the formatting culture that must be used in the application. |
Remarks
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.
Example
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:
- Add a new Window Controller.
- Set the Controller’s WindowController.TargetWindowType property to
Main. - Add
chooseLanguageandchooseFormattingCultureSingle Choice Actions. - Override the Controller’s
OnActivatedmethod to populate Actions with Items. - Subscribe to the Execute event for both Actions. In event handlers, call SetLanguage(String) and
SetFormattingCulture(String)methods, respectively.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using System.Globalization;
//...
public class ChangeLanguageController : WindowController {
private string defaultCulture;
private string defaultFormattingCulture;
SingleChoiceAction chooseLanguage;
SingleChoiceAction chooseFormattingCulture;
public ChangeLanguageController() {
TargetWindowType = WindowType.Main;
chooseLanguage = new SingleChoiceAction(this, "ChooseLanguage", "View");
chooseLanguage.Execute += chooseLanguage_Execute;
chooseFormattingCulture = new SingleChoiceAction(this, "ChooseFormattingCulture", "View");
chooseFormattingCulture.Execute += chooseFormattingCulture_Execute;
}
protected override void OnActivated() {
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"));
base.OnActivated();
}
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);
}
}