XafApplication.SetFormattingCulture(String) Method
Sets the specified formatting culture for the current application.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v25.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| formattingCultureName | String | The name of the formatting culture that must be used in the application. |
Remarks
A .NET 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.
Important
The SetFormattingCulture method does not work for XAF ASP.NET Core Blazor UI applications. Refer to the following topics for information on how to localize XAF ASP.NET Core Blazor UI applications:
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.
- Invoke the Controller’s Designer. Set the Controller’s WindowController.TargetWindowType property to
Main. - Drag the
SingleChoiceActionitem from the Toolbox’ DX: XAF Actions page to the Controller’s Designer area. Set the Action’sNameandIDproperties (here,ChooseLanguage), theCaptionproperty (here,Choose Language) and the ActionBase.Category property (here,Tools). - Drag and drop one more
SingleChoiceActionitem. Specify its properties correspondingly. Here, theNameandIDproperties are set toChooseFormattingCulture, and theCaptionproperty is set toChoose Formatting Culture. - Subscribe to the Controller’s Controller.Activated event. In the event handler, populate the ChoiceActionBase.Items collection of the Controller’s Actions with the required items (see the code).
- Subscribe to the SingleChoiceAction.Execute event of the Controller’s Actions. In the event handlers, call the XafApplication.SetLanguage and
XafApplication.SetFormattingCulturemethods, 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);
}
}