Skip to main content
.NET 6.0+

XafApplication.SetFormattingCulture(String) Method

Sets the specified formatting culture for the current application.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v23.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public void SetFormattingCulture(
    string formattingCultureName
)

Parameters

Name Type Description
formattingCultureName String

A string value representing the name of the formatting culture that must be used in the application.

Remarks

By default, 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.

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:

    1. Add a new Window Controller.
    1. Invoke the Controller’s Designer. Set the Controller’s WindowController.TargetWindowType property to Main.
    1. Drag the 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).
    1. Drag and drop one more 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.
    1. 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).
    1. Subscribe to the SingleChoiceAction.Execute event of the Controller’s Actions. In the event handlers, call the XafApplication.SetLanguage and 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