Skip to main content
All docs
V24.2
.NET 8.0+
  • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

IXafCultureInfoService.SetCultureAsync(String) Method

Saves the specified culture in CookieRequestCultureProvider.DefaultCookie and reloads the page.

Namespace: DevExpress.ExpressApp.Blazor.Services

Assembly: DevExpress.ExpressApp.Blazor.v24.2.dll

NuGet Package: DevExpress.ExpressApp.Blazor

Declaration

Task SetCultureAsync(
    string culture
)

Parameters

Name Type Description
culture String

A new culture.

Returns

Type Description
Task

A task that sets a new culture.

Remarks

After calling the SetCultureAsync method, the XafApplication is recreated in a new culture. The new culture is read from cookies in RequestLocalizationMiddleware.

After calling the SetCultureAsync method, the application is reloaded even if the new culture is the same as the previous culture (that means that the culture was not changed).

Learn more: How to: Localize an XAF .NET Application (Blazor and WinForms)

Example

The code sample below demonstrates how to use the SetCultureAsync method to change the application localization.

File:
MySolution.Blazor.Server\Controllers\GermanCultureController.cs

using DevExpress.ExpressApp; 
using DevExpress.ExpressApp.Actions; 
using DevExpress.ExpressApp.Blazor; 
using DevExpress.ExpressApp.Blazor.Services; 
using DevExpress.Persistent.Base; 
// ...
public class GermanCultureController : ViewController { 
    BlazorApplication BlazorApplication => (BlazorApplication)Application; 
    IXafCultureInfoService CultureInfoService => (IXafCultureInfoService)BlazorApplication.ServiceProvider.GetService(typeof(IXafCultureInfoService)); 
    public GermanCultureController() { 
        SimpleAction myAction = new SimpleAction(this, "SetGermanCulture", PredefinedCategory.Edit); 
        myAction.Execute += async (s, e) => await CultureInfoService.SetCultureAsync("de"); 
    } 
} 
See Also