[英]c# - localization - changing language in wpf app
我正在制作一些wpf應用程序,我需要更改語言的選項。 我的解決方案中有一個名為Resorces的文件夾,我存儲了所有resx文件 - 實際上是language.resx和language.en-EN.resx。 我的XAML看起來像:
<Window x:Class="CoinCatalogue.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CoinCatalogue"
xmlns:resx="clr-namespace:CoinCatalogue.Resources"
mc:Ignorable="d"
Title="{x:Static resx:language.WindowName}" Height="480" Width="640">
<Grid>
<Menu x:Name="menu" HorizontalAlignment="Left" Height="auto" VerticalAlignment="Top" Width="517">
<MenuItem x:Name="File" Header="{x:Static resx:language.File}">
<MenuItem x:Name="Open" Header="{x:Static resx:language.Open}"/>
</MenuItem>
</Menu>
</Grid>
一切都很好 - 我可以在應用程序中訪問字符串。 在我的主要課程中,我試圖用線改變文化:
language.Culture = new System.Globalization.CultureInfo("en-EN");
但是沒有發生在我的應用程序上。 這一行在InitializeComponent();之前。
我究竟做錯了什么? 我正在使用Visual Studio 2015. /以這種方式更改應用程序語言是個好主意嗎?
我認為你如何改變文化是一個問題。
我只是將快速示例放在一起,我有以下resx文件:
Resources.en-US.resx
Resources.fr-FR.resx
Resources.resx
如果我在不嘗試更改文化的情況下運行應用程序,我會從Resources.en-US.resx
文件中獲取字符串,因為這是我的默認設置。 如果我在InitializeComponent
之前添加此代碼,我的字符串來自Resources.fr-FR.resx
文件:
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fr-FR");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("fr-FR");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.