我正在编写一个 WPF 应用程序,但在文化方面遇到了一些困难。
我想知道当没有明确设置值时,.NET 应用程序从哪里获取 CurrentThread.CurrentCulture 的值。它不是来自 Windows 区域性信息,因为我已将其从 en-US 更改为 en-GB,但在运行时没有注意到应用程序有任何变化。
请帮忙!
标记
最佳答案
来自 the fine manual :
See the
CultureInfo.CurrentCulture
property to learn how a thread's default culture is determined, and how users set culture information for their computers.
How a Thread's Culture Is Determined
When a thread is started, its culture is initially determined as follows:
By retrieving the culture that is specified by the
DefaultThreadCurrentCulture
property in the application domain in which the thread is executing, if the property value is notnull
.By calling the Windows
GetUserDefaultLocaleName
function.Note that if you set a specific culture that is different from the system-installed culture or the user's preferred culture, and your application starts multiple threads, the current culture of those threads will be the culture that is returned by the
GetUserDefaultLocaleName
function, unless you assign a culture to theDefaultThreadCurrentCulture
property in the application domain in which the thread is executing.For more information about how the culture of a thread is determined, see the "Culture and Threads" section in the
CultureInfo
topic.
I didn't budget for another click, but clicked anyway .
Culture and Threads
When a new application thread is started, its current culture and current UI culture are defined by the current system culture, and not by the current thread culture. The following example illustrates the difference. It sets the current culture and current UI culture of an application thread to the French (France) culture (fr-FR). If the current culture is already fr-FR, the example sets it to the English (United States) culture (en-US). It displays three random numbers as currency values and then creates a new thread, which, in turn, displays three more random numbers as currency values. But as the output from the example shows, the currency values displayed by the new thread do not reflect the formatting conventions of the French (France) culture, unlike the output from the main application thread.
请注意,它说当一个新的应用程序线程启动时。所以,鉴于你说:
It's not from the Windows culture info because I have changed that from en-US to en-GB without noticing any change in the application when running.
您可能想要查看 this answer .
关于c# - 在 .NET 应用程序中在哪里设置默认区域性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17567298/