Udostępnij za pośrednictwem


CultureInfo.CurrentUICulture Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared ReadOnly Property CurrentUICulture As CultureInfo
public static CultureInfo CurrentUICulture { get; }

Property Value

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

Remarks

The current UI culture is a property of the executing thread. This property returns the value of the System.Threading.Thread.CurrentThread.CurrentUICulture.property.

Explicitly Setting the Current UI Culture

Although the CultureInfo.CurrentUICulture property is read-only, you can change its value by explicitly setting the Thread.CurrentUICulture property of the current thread. 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").

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.

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 by using the system's default culture.

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 default system culture.

Examples

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

Imports System.Globalization
Imports System.Threading

Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Displays the name of the CurrentCulture of the current thread.
      outputBlock.Text += String.Format("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name) & vbCrLf

      ' Changes the CurrentCulture of the current thread to th-TH.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("th-TH")
      outputBlock.Text += String.Format("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name) & vbCrLf

      ' Displays the name of the CurrentUICulture of the current thread.
      outputBlock.Text += String.Format("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name) & vbCrLf

      ' Changes the CurrentUICulture of the current thread to ja-JP.
      Thread.CurrentThread.CurrentUICulture = New CultureInfo("ja-JP")
      outputBlock.Text += String.Format("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name) & vbCrLf
   End Sub
End Class
'This code produces the following output:
'       CurrentCulture is en-US.
'       CurrentCulture is now th-TH.
'       CurrentUICulture is en-US.
'       CurrentUICulture is now ja-JP.
using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Displays the name of the CurrentCulture of the current thread.
      outputBlock.Text += String.Format("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name) + "\n";

      // Changes the CurrentCulture of the current thread to th-TH.
      Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
      outputBlock.Text += String.Format("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name) + "\n";

      // Displays the name of the CurrentUICulture of the current thread.
      outputBlock.Text += String.Format("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name) + "\n";

      // Changes the CurrentUICulture of the current thread to ja-JP.
      Thread.CurrentThread.CurrentUICulture = new CultureInfo("ja-JP");
      outputBlock.Text += String.Format("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name) + "\n";
   }
}
/*
This code produces the following output:
   CurrentCulture is en-US.
   CurrentCulture is now th-TH.
   CurrentUICulture is en-US.
   CurrentUICulture is now ja-JP.
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.