Culture-Specific Formatting

In .NET applications, formatting options for information like currency, numbers, and dates are not related to the application's UI language specified by the Thread.CurrentUICulture property value. The formatting options that are set in the current user's operating system or passed by the Internet browser are used by default. You can enforce use of a specific formatting culture instead of the default, or customize some of the default settings.

Change the Formatting Culture

You can set another formatting culture using the XafApplication.SetFormattingCulture method, which changes the Thread.CurrentCulture value. The following code demonstrates how to do this in a Windows Forms application project's Program.cs (Program.vb) file:

static void Main() {
    // ...
    MySolutionWindowsFormsApplication winApplication = 
        new MySolutionWindowsFormsApplication();
    winApplication.SetFormattingCulture("de");
    // ...
}

The following image, illustrates the result.

CustomizeCultureWin2

Analogously, you can change the formatting culture an ASP.NET application project's Global.asax.cs (Global.asax.vb) file:

protected void Session_Start(Object sender, EventArgs e) {
    WebApplication.SetInstance(Session, new MySolutionAspNetApplication());
    WebApplication.Instance.SetFormattingCulture("de");
    // ...
}

Override the Default Formatting Options

You can override the default formatting options in the XafApplication.CustomizeFormattingCulture event handler. The following code demonstrates how to do this in a Windows Forms application project's Program.cs (Program.vb) file:

public static void Main() {
    //...
    MySolutionWindowsFormsApplication winApplication = new MySolutionWindowsFormsApplication(); 
    winApplication.CustomizeFormattingCulture += 
        new EventHandler<CustomizeFormattingCultureEventArgs>(
            winApplication_CustomizeFormattingCulture);
      // ...
}
static void winApplication_CustomizeFormattingCulture(
    object sender, CustomizeFormattingCultureEventArgs e) {
    e.FormattingCulture.NumberFormat.CurrencySymbol = "USD";
}

The following image illustrates the currency symbol before and after implementing the code above:

CustomizeCultureWin

The following code demonstrates how override the default formatting options in an ASP.NET application project's Global.asax.cs (Global.asax.vb) file:

protected void Session_Start(Object sender, EventArgs e) {
    WebApplication.SetInstance(Session, new MySolutionAspNetApplication());
    WebApplication.Instance.CustomizeFormattingCulture += Instance_CustomizeFormattingCulture;
    // ...
    WebApplication.Instance.Setup();
    WebApplication.Instance.Start();
}

The following image illustrates the currency symbol after implementing the code above:

CustomizeCultureWeb