XafApplication.SetFormattingCulture(String) Method
Sets the specified formatting culture for the current application.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
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:
- Add a new Window Controller.
- Invoke the Controller’s Designer. Set the Controller’s WindowController.TargetWindowType property to Main.
- 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).
- 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.
- 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.SetFormattingCulture
methods, respectively, passing the currently selected Action Item (see the code).
- Subscribe to the SingleChoiceAction.Execute event of the Controller’s Actions. In the event handlers, call the XafApplication.SetLanguage and
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);
}
}