Export (0) Print
Expand All

CultureInfo.CurrentUICulture Property

Gets or sets the CultureInfo object that represents the current user interface culture used by the Resource Manager to look up culture-specific resources at run time.

Namespace:  System.Globalization
Assemblies:   mscorlib (in mscorlib.dll)
  System.Globalization (in System.Globalization.dll)

public static CultureInfo CurrentUICulture { get; set; }

Property Value

Type: System.Globalization.CultureInfo
The culture used by the Resource Manager to look up culture-specific resources at run time.

ExceptionCondition
ArgumentNullException

The property is set to null.

ArgumentException

The property is set to a culture name that cannot be used to locate a resource file. Resource filenames can include only letters, numbers, hyphens, or underscores.

The current UI culture is a per-thread property. That is, each thread has its own current UI culture. This property is equivalent to retrieving or, starting with the .NET Framework 4.6 Preview, setting the CultureInfo object assigned to the System.Threading.Thread.CurrentThread.CurrentUICulture property. When a thread is started, its UI culture is initially determined as follows:

  • By retrieving the culture that is specified by the DefaultThreadCurrentUICulture property in the application domain in which the thread is executing, if the property value is not null.

  • By calling the Windows GetUserDefaultUILanguage function.

NoteNote

In the .NET Compact Framework, the CurrentUICulture property is read-only. The current UI culture is determined by the system's regional settings and cannot be changed programmatically.

Starting with the .NET Framework 4.6 Preview, to change the user interface culture used by a thread, set the Thread.CurrentUICulture property to the new culture. If you explicitly change a thread's UI culture in this way, that change persists if the thread crosses application domain boundaries.

NoteNote

In the .NET Framework 4.5.2 and earlier versions, the CurrentUICulture property is read-only; that is, you can retrieve the property value, but you cannot set it. To change the current UI culture, you assign the CultureInfo object that represents the new UI culture to the Thread.CurrentThread.CurrentUICulture property. Starting with the .NET Framework 4.6 Preview, the CultureInfo.CurrentUICulture property is read-write; you can both set and retrieve the property's value. If you do set the property value to a CultureInfo object that represents a new culture, the value of the Thread.CurrentThread.CurrentCulture property also changes.

Explicitly Setting the Current UI Culture

Starting with the .NET Framework 4.6 Preview, you can change the current UI culture by assigning a CultureInfo object that represents the new culture to the iCultureInfo.CurrentUICulture property. The current UI culture can be set to either a specific culture (such as en-US or de-DE) or to a neutral culture (such as en or de). The following example sets the current UI culture to fr-FR or French (France).

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      Console.WriteLine("The current UI culture: {0}", 
                        CultureInfo.CurrentUICulture.Name);

      CultureInfo.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
      Console.WriteLine("The current UI culture: {0}", 
                        CultureInfo.CurrentUICulture.Name);
   }
}
// The example displays output like the following: 
//       The current UI culture: en-US 
//       The current UI culture: fr-FR

In a multithreaded application, you can explicitly set the UI culture of any thread by assigning a CultureInfo object that represents that culture to the thread's Thread.CurrentUICulture property. If the thread whose culture you want to set is the current thread, you can assign the new culture to the CultureInfo.CurrentUICulture property. When the UI culture of a thread is set explicitly, that thread retains the same culture even if it crosses application domain boundaries and executes code in another application domain.

Implicitly Setting the Current UI Culture

When a thread, including the main application thread, is first created, by default its current UI culture is set as follows:

  • By using the culture defined by the DefaultThreadCurrentUICulture property for the current application domain if the property value is not null.

  • By using the system's default culture. On systems that use the Windows operating system, the common language runtime calls the Windows GetUserDefaultUILanguage function to set the current UI culture. GetUserDefaultUILanguage returns the default UI culture set by the user. If the user has not set a default UI language, it returns the culture originally installed on the system.

If the thread crosses application boundaries and executes code in another application domain, its culture is determined in the same way as that of a newly created thread.

Note that if you set a specific UI culture that is different from the system-installed UI culture or the user's preferred UI culture, and your application starts multiple threads, the current UI culture of those threads will be the culture returned by the GetUserDefaultUILanguage function, unless you assign a culture to the DefaultThreadCurrentUICulture property in the application domain in which the thread is executing.

Security Considerations

Changing the culture of the current thread requires a SecurityPermission permission with the ControlThread value set.

Caution noteCaution

Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code.

The following code example demonstrates how to change the CurrentCulture and CurrentUICulture of the current thread.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft