CultureInfo.CurrentUICulture Özellik

Tanım

CultureInfoÇalışma zamanında kültüre özgü kaynakları aramak için kaynak yöneticisi tarafından kullanılan geçerli kullanıcı Arabirimi kültürünü temsil eden nesneyi alır veya ayarlar.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.

public:
 static property System::Globalization::CultureInfo ^ CurrentUICulture { System::Globalization::CultureInfo ^ get(); void set(System::Globalization::CultureInfo ^ value); };
public:
 static property System::Globalization::CultureInfo ^ CurrentUICulture { System::Globalization::CultureInfo ^ get(); };
public static System.Globalization.CultureInfo CurrentUICulture { get; set; }
public static System.Globalization.CultureInfo CurrentUICulture { get; }
member this.CurrentUICulture : System.Globalization.CultureInfo with get, set
member this.CurrentUICulture : System.Globalization.CultureInfo
Public Shared Property CurrentUICulture As CultureInfo
Public Shared ReadOnly Property CurrentUICulture As CultureInfo

Özellik Değeri

CultureInfo

Çalışma zamanında kültüre özgü kaynakları aramak için Kaynak Yöneticisi tarafından kullanılan kültür.The culture used by the Resource Manager to look up culture-specific resources at run time.

Özel durumlar

Özelliği olarak ayarlanır null .The property is set to null.

Özelliği, bir kaynak dosyası bulmak için kullanılamayan bir kültür adına ayarlanır.The property is set to a culture name that cannot be used to locate a resource file. Kaynak dosya adları yalnızca harf, sayı, kısa çizgi veya alt çizgi içerebilir.Resource filenames can include only letters, numbers, hyphens, or underscores.

Örnekler

Aşağıdaki kod örneği, CurrentCulture CurrentUICulture geçerli iş parçacığının ve öğesinin nasıl değiştirileceğini gösterir.The following code example demonstrates how to change the CurrentCulture and CurrentUICulture of the current thread.

using namespace System;
using namespace System::Globalization;
using namespace System::Threading;

int main()
{
   // Display the name of the current thread culture.
   Console::WriteLine("CurrentCulture is {0}.", CultureInfo::CurrentCulture->Name);
   
   // Change the current culture to th-TH.
   CultureInfo::CurrentCulture = gcnew CultureInfo("th-TH",false);
   Console::WriteLine("CurrentCulture is now {0}.", CultureInfo::CurrentCulture->Name);
   
   // Displays the name of the CurrentUICulture of the current thread.
   Console::WriteLine("CurrentUICulture is {0}.", CultureInfo::CurrentCulture->Name);
   
   // Changes the CurrentUICulture of the current thread to ja-JP.
   CultureInfo::CurrentUICulture = gcnew CultureInfo("ja-JP",false);
   Console::WriteLine("CurrentUICulture is now {0}.", CultureInfo::CurrentCulture->Name);
}
// The example displays 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 Main()
   {
      // Display the name of the current thread culture.
      Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name);

      // Change the current culture to th-TH.
      CultureInfo.CurrentCulture = new CultureInfo("th-TH", false);
      Console.WriteLine("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name);

      // Display the name of the current UI culture.
      Console.WriteLine("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name);

      // Change the current UI culture to ja-JP.
      CultureInfo.CurrentUICulture = new CultureInfo( "ja-JP", false );
      Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name);
   }
}
// The example displays the following output:
//       CurrentCulture is en-US.
//       CurrentCulture is now th-TH.
//       CurrentUICulture is en-US.
//       CurrentUICulture is now ja-JP.
Imports System.Globalization
Imports System.Threading

Public Module Example
   Public Sub Main()

      ' Display the name of the current thread culture.
      Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name)

      ' Change the current culture to th-TH.
      CultureInfo.CurrentCulture = New CultureInfo("th-TH", False)
      Console.WriteLine("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name)

      ' Display the name of the current UI culture.
      Console.WriteLine("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name)

      ' Change the current UI culture to ja-JP.
      CultureInfo.CurrentUICulture = New CultureInfo("ja-JP", False)
      Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name)
   End Sub 
End Module
' The example displays the following output:
'       CurrentCulture is en-US.
'       CurrentCulture is now th-TH.
'       CurrentUICulture is en-US.
'       CurrentUICulture is now ja-JP.

Açıklamalar

Geçerli UI kültürü iş parçacığı başına bir özelliktir.The current UI culture is a per-thread property. Diğer bir deyişle, her iş parçacığının kendi geçerli kullanıcı arabirimi kültürü vardır.That is, each thread has its own current UI culture. Bu özellik, .NET Framework 4,6 ile başlayarak, özelliğe atanmış nesneyi ayarlayarak alma veya alma ile eşdeğerdir CultureInfo System.Threading.Thread.CurrentThread.CurrentUICulture .This property is equivalent to retrieving or, starting with the .NET Framework 4.6, setting the CultureInfo object assigned to the System.Threading.Thread.CurrentThread.CurrentUICulture property. Bir iş parçacığı başlatıldığında, Kullanıcı arabirimi kültürü başlangıçta aşağıdaki gibi belirlenir:When a thread is started, its UI culture is initially determined as follows:

  • Özelliği tarafından belirtilen kültürü alarak DefaultThreadCurrentUICulture , iş parçacığının yürütüldüğü uygulama etki alanında, özellik değeri değilse null .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.

  • İş parçacığı, görev tabanlı zaman uyumsuz bir işlem yürüten bir iş parçacığı havuzu iş parçacığıdır ve uygulama .NET Framework 4,6 veya sonraki bir .NET Framework sürümünü hedefliyorsa, Kullanıcı arabirimi kültürü çağıran iş parçacığının UI kültürü tarafından belirlenir.If the thread is a thread pool thread that is executing a task-based asynchronous operation and the app targets the .NET Framework 4.6 or a later version of the .NET Framework, its UI culture is determined by the UI culture of the calling thread. Aşağıdaki örnek, geçerli UI kültürünü Portekizce (Brezilya) olarak değiştirir ve altı görevi başlatır, her biri iş parçacığı KIMLIĞINI, görev KIMLIĞINI ve geçerli kullanıcı Arabirimi kültürünü görüntüler.The following example changes the current UI culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current UI culture. Görevlerin (ve iş parçacıklarının) her biri, çağıran iş parçacığının Kullanıcı Arabirimi kültürünü devraldı.Each of the tasks (and the threads) has inherited the UI culture of the calling thread.

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Runtime.Versioning;
    using System.Threading;
    using System.Threading.Tasks;
    
    [assembly:TargetFramework(".NETFramework,Version=v4.6")]
    
    public class Example
    {
       public static async Task Main()
       {
          var tasks = new List<Task>();
          Console.WriteLine("The current UI culture is {0}",
                            Thread.CurrentThread.CurrentUICulture.Name);
          Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR");
          // Change the current UI culture to Portuguese (Brazil).
          Console.WriteLine("Current UI culture changed to {0}",
                            Thread.CurrentThread.CurrentUICulture.Name);
          Console.WriteLine("Application thread is thread {0}",
                            Thread.CurrentThread.ManagedThreadId);
          // Launch six tasks and display their current culture.
          for (int ctr = 0; ctr <= 5; ctr++)
             tasks.Add(Task.Run( () => {
                                   Console.WriteLine("UI Culture of task {0} on thread {1} is {2}",
                                                     Task.CurrentId,
                                                     Thread.CurrentThread.ManagedThreadId,
                                                     Thread.CurrentThread.CurrentUICulture.Name);
                                } ));
    
          await Task.WhenAll(tasks.ToArray());
       }
    }
    // The example displays output like the following:
    //     The current culture is en-US
    //     Current culture changed to pt-BR
    //     Application thread is thread 9
    //     Culture of task 2 on thread 11 is pt-BR
    //     Culture of task 1 on thread 10 is pt-BR
    //     Culture of task 3 on thread 11 is pt-BR
    //     Culture of task 5 on thread 11 is pt-BR
    //     Culture of task 6 on thread 11 is pt-BR
    //     Culture of task 4 on thread 10 is pt-BR
    
    Imports System.Collections.Generic
    Imports System.Globalization
    Imports System.Runtime.Versioning
    Imports System.Threading
    Imports System.Threading.Tasks
    
    <assembly:TargetFramework(".NETFramework,Version=v4.6")>
    
    Module Example
       Public Sub Main()
          Dim tasks As New List(Of Task)
          Console.WriteLine("The current UI culture is {0}", 
                            Thread.CurrentThread.CurrentUICulture.Name)
          Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-BR")
          ' Change the current UI culture to Portuguese (Brazil).
          Console.WriteLine("Current culture changed to {0}",
                            Thread.CurrentThread.CurrentUICulture.Name)
          Console.WriteLine("Application thread is thread {0}",
                            Thread.CurrentThread.ManagedThreadId)
          ' Launch six tasks and display their current culture.
          For ctr As Integer = 0 to 5
             tasks.Add(Task.Run(Sub()
                                   Console.WriteLine("Culture of task {0} on thread {1} is {2}",
                                                     Task.CurrentId, 
                                                     Thread.CurrentThread.ManagedThreadId,
                                                     Thread.CurrentThread.CurrentUICulture.Name)
                                End Sub))                     
          Next
          Task.WaitAll(tasks.ToArray())
       End Sub
    End Module
    ' The example displays output like the following:
    '     The current culture is en-US
    '     Current culture changed to pt-BR
    '     Application thread is thread 9
    '     Culture of task 2 on thread 11 is pt-BR
    '     Culture of task 1 on thread 10 is pt-BR
    '     Culture of task 3 on thread 11 is pt-BR
    '     Culture of task 5 on thread 11 is pt-BR
    '     Culture of task 6 on thread 11 is pt-BR
    '     Culture of task 4 on thread 10 is pt-BR
    

    Daha fazla bilgi için, konusunun "Kültür ve görev tabanlı zaman uyumsuz işlemler" bölümüne bakın CultureInfo .For more information, see the "Culture and task-based asynchronous operations" section in the CultureInfo topic.

  • Windows GetUserDefaultUILanguage işlevini çağırarak.By calling the Windows GetUserDefaultUILanguage function.

Not

.NET Compact Framework, CurrentUICulture özelliği salt okunurdur.In the .NET Compact Framework, the CurrentUICulture property is read-only. Geçerli UI kültürü sistemin bölgesel ayarları tarafından belirlenir ve program aracılığıyla değiştirilemez.The current UI culture is determined by the system's regional settings and cannot be changed programmatically.

4,6 .NET Framework başlayarak, bir iş parçacığı tarafından kullanılan Kullanıcı Arabirimi kültürünü değiştirmek için, Thread.CurrentUICulture özelliği yeni kültür olarak ayarlayın.Starting with the .NET Framework 4.6, to change the user interface culture used by a thread, set the Thread.CurrentUICulture property to the new culture. Bir iş parçacığının UI kültürünü açıkça bu şekilde değiştirirseniz, iş parçacığı uygulama etki alanı sınırlarını aştığında bu değişiklik devam ettirir.If you explicitly change a thread's UI culture in this way, that change persists if the thread crosses application domain boundaries.

Not

.NET Framework 4.5.2 ve önceki sürümlerde, CurrentUICulture özelliği salt okunurdur; diğer bir deyişle, özellik değerini alabilirsiniz, ancak bunu ayarlayamazsınız.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. Geçerli Kullanıcı Arabirimi kültürünü değiştirmek için, CultureInfo yenı UI kültürünü temsil eden nesneyi Thread.CurrentThread.CurrentUICulture özelliğine atarsınız.To change the current UI culture, you assign the CultureInfo object that represents the new UI culture to the Thread.CurrentThread.CurrentUICulture property. .NET Framework 4,6 ile başlayarak, CultureInfo.CurrentUICulture özelliği okuma-yazma olur; özelliğin değerini hem ayarlayabilir hem de alabilirsiniz.Starting with the .NET Framework 4.6, the CultureInfo.CurrentUICulture property is read-write; you can both set and retrieve the property's value. Özellik değerini CultureInfo Yeni bir kültürü temsil eden bir nesneye ayarlarsanız, Thread.CurrentThread.CurrentCulture özelliğin değeri de değişir.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.

Bu bölümdeki konular:In this section:

Geçerli Kullanıcı Arabirimi kültürünü alma Getting the Current UI Culture
Geçerli Kullanıcı Arabirimi kültürünü açıkça ayarlama Explicitly Setting the Current UI Culture
Geçerli Kullanıcı Arabirimi kültürünü örtülü olarak ayarlama Implicitly Setting the Current UI Culture
Güvenlik konuları Security Considerations
Geçerli UI kültürü ve Windows uygulamalarıThe Current UI Culture and Windows apps

Geçerli Kullanıcı Arabirimi kültürünü almaGetting the Current UI Culture

CultureInfo.CurrentUICultureÖzelliği iş parçacığı başına ayardır; diğer bir deyişle, her bir iş parçacığının kendı UI kültürü olabilir.The CultureInfo.CurrentUICulture property is a per-thread setting; that is, each thread can have its own UI culture. CultureInfo.CurrentUICultureAşağıdaki örnekte gösterildiği gibi, özelliğin değerini alarak geçerli iş PARÇACıĞıNıN UI kültürünü elde edersiniz.You get the UI culture of the current thread by retrieving the value of the CultureInfo.CurrentUICulture property, as the following example illustrates.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo culture = CultureInfo.CurrentUICulture;
      Console.WriteLine("The current UI culture is {0} [{1}]",
                        culture.NativeName, culture.Name);
   }
}
// The example displays output like the following:
//       The current UI culture is English (United States) [en-US]
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim culture As CultureInfo = CultureInfo.CurrentCulture
      Console.WriteLine("The current UI culture is {0} [{1}]",
                        culture.NativeName, culture.Name)
   End Sub
End Module
' The example displays output like the following:
'     The current UI culture is English (United States) [en-US]

Geçerli iş parçacığının UI kültürünün değerini özelliğinden de alabilirsiniz Thread.CurrentUICulture .You can also retrieve the value of the current thread's UI culture from the Thread.CurrentUICulture property.

Geçerli Kullanıcı Arabirimi Kültürünü Açık Olarak AyarlamaExplicitly Setting the Current UI Culture

.NET Framework 4,6 ' den başlayarak, CultureInfo özelliğe yeni kültürü temsil eden bir nesne atayarak geçerli kullanıcı Arabirimi kültürünü değiştirebilirsiniz CultureInfo.CurrentUICulture .Starting with the .NET Framework 4.6, you can change the current UI culture by assigning a CultureInfo object that represents the new culture to the CultureInfo.CurrentUICulture property. Geçerli Kullanıcı arabirimi kültürü belirli bir kültüre (örneğin, en-US veya de-DE) ya da bağımsız bir kültüre (en veya de gibi) ayarlanabilir.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). Aşağıdaki örnek, geçerli kullanıcı Arabirimi kültürünü fr-FR veya Fransızca (Fransa) olarak ayarlar.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
Imports System.Globalization
Imports System.Threading

Module Example
   Public Sub 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)
   End Sub
End Module
' The example displays output like the following:
'       The current UI culture: en-US
'       The current UI culture: fr-FR

Çok iş parçacıklı bir uygulamada, CultureInfo Bu kültürü temsil eden bir nesneyi iş parçacığının özelliğine atayarak herhangi bir iş parçacığının Kullanıcı Arabirimi kültürünü açıkça ayarlayabilirsiniz Thread.CurrentUICulture .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. Kültürünü ayarlamak istediğiniz iş parçacığı geçerli iş parçacığı ise, yeni kültürü CultureInfo.CurrentUICulture özelliğe atayabilirsiniz.If the thread whose culture you want to set is the current thread, you can assign the new culture to the CultureInfo.CurrentUICulture property. Bir iş parçacığının UI kültürü açıkça ayarlandığında, bu iş parçacığı uygulama etki alanı sınırlarını aşsa ve kodu başka bir uygulama etki alanında yürüten halde aynı kültürü korur.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.

Geçerli Kullanıcı Arabirimi Kültürünü Örtülü Olarak AyarlamaImplicitly Setting the Current UI Culture

Ana uygulama iş parçacığı dahil bir iş parçacığı ilk oluşturulduğunda, varsayılan olarak geçerli kullanıcı arabirimi kültürü şu şekilde ayarlanır:When a thread, including the main application thread, is first created, by default its current UI culture is set as follows:

  • DefaultThreadCurrentUICultureÖzellik değeri değilse, geçerli uygulama etki alanı için özelliği tarafından tanımlanan kültürü kullanarak null .By using the culture defined by the DefaultThreadCurrentUICulture property for the current application domain if the property value is not null.

  • Sisteminin varsayılan kültürünü kullanarak.By using the system's default culture. Windows işletim sistemini kullanan sistemlerde, ortak dil çalışma zamanı, GetUserDefaultUILanguage Geçerli Kullanıcı Arabirimi kültürünü ayarlamak Için Windows işlevini çağırır.On systems that use the Windows operating system, the common language runtime calls the Windows GetUserDefaultUILanguage function to set the current UI culture. GetUserDefaultUILanguage Kullanıcı tarafından ayarlanan varsayılan kullanıcı Arabirimi kültürünü döndürür.GetUserDefaultUILanguage returns the default UI culture set by the user. Kullanıcı varsayılan bir kullanıcı arabirimi dili ayarlanmamışsa, sistemde başlangıçta yüklü olan kültürü döndürür.If the user has not set a default UI language, it returns the culture originally installed on the system.

İş parçacığı uygulama sınırlarını aşalıyorsa ve kodu başka bir uygulama etki alanında çalıştırırsa, kültürü yeni oluşturulan iş parçacığıyla aynı şekilde belirlenir.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.

Sistem tarafından yüklenen UI kültürü veya kullanıcının tercih edilen kullanıcı ARABIRIMI kültüründen farklı bir kullanıcı arabirimi kültürü ayarlarsanız ve uygulamanız birden çok iş parçacığı başlattığında, GetUserDefaultUILanguage DefaultThreadCurrentUICulture iş parçacığının yürütüldüğü uygulama etki alanındaki özelliğe bir kültür atamadığınız müddetçe, bu iş parçacıklarının geçerli kullanıcı arabirimi kültürü işlevin döndürdüğü kültür olacaktır.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.

Güvenlikle İlgili Dikkat Edilmesi GerekenlerSecurity Considerations

Geçerli iş parçacığının kültürünün değiştirilmesi SecurityPermission ControlThread değer kümesine izin gerektirir.Changing the culture of the current thread requires a SecurityPermission permission with the ControlThread value set.

Dikkat

İş parçacıklarından ilişkili güvenlik durumu nedeniyle iş parçacıklarını düzenleme tehlikeli.Manipulating threads is dangerous because of the security state associated with threads. Bu nedenle, bu izin yalnızca güvenilir koda ve yalnızca gerekli şekilde verilmelidir.Therefore, this permission should be given only to trustworthy code, and then only as necessary. Yarı güvenilir koddaki iş parçacığı kültürünü değiştiremezsiniz.You cannot change thread culture in semi-trusted code.

Geçerli UI kültürü ve UWP uygulamalarıThe current UI culture and UWP apps

Evrensel Windows Platformu (UWP) uygulamalarında, CurrentUICulture özelliği .NET Framework ve .NET Core uygulamalarında olduğu gibi, salt yazılır. geçerli kültürü almak ve ayarlamak için de kullanabilirsiniz.In Universal Windows Platform (UWP) apps, the CurrentUICulture property is read-write, just as it is in .NET Framework and .NET Core apps; you can use it both to get and to set the current culture. Ancak, UWP uygulamaları geçerli kültür ile geçerli kullanıcı Arabirimi kültürünü ayırt etmez.However, UWP apps do not distinguish between the current culture and the current UI culture. CurrentCultureVe CurrentUICulture Özellikleri, Windows. ApplicationModel. resources. Core. ResourceManager. DefaultContext. Languages koleksiyonundaki ilk değere eşlenir.The CurrentCulture and CurrentUICulture properties map to the first value in the Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages collection.

.NET Framework ve .NET Core uygulamalarında, geçerli UI kültürü iş parçacığı başına ayardır ve CurrentUICulture özelliği yalnızca geçerli iş parçacığının Kullanıcı Arabirimi kültürünü yansıtır.In .NET Framework and .NET Core apps, the current UI culture is a per-thread setting, and the CurrentUICulture property reflects the UI culture of the current thread only. UWP uygulamalarında geçerli kültür, genel bir ayar olan Windows. ApplicationModel. resources. Core. ResourceManager. DefaultContext. Languages özelliğine eşlenir.In UWP apps, the current culture maps to the Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages property, which is a global setting. Özelliği ayarlamak CurrentCulture tüm uygulamanın kültürünü değiştirir; kültür iş parçacığı başına temelinde ayarlanamaz.Setting the CurrentCulture property changes the culture of the entire app; culture cannot be set on a per-thread basis.

Şunlara uygulanır

Ayrıca bkz.