0
我必須在當前使用C#的WPF/XAML中構建應用程序。
我也沒有寫這段代碼,所以我不能解釋它的一切。如何在WPF/XAML中更改語言
我需要代碼將應用程序的語言更改爲用戶在主菜單中選擇的任何內容。這是在C#中工作的代碼:
public static void TranslateForm(string Language, Form f)
{
try
{
string Sprachtext = string.Empty;
clstools tools = new clstools(string.Format(string.Format(clsGlobal.CONNECTION_STRING, clsGlobal.TNSNames,
clsGlobal.DBUser, clsGlobal.DBPassword)), clsGlobal.IDOPERATOR);
//caption text of the form :-)
try
{
if (f.Tag != null)
{
if (tools.IsNumeric(f.Tag.ToString()) == true)
{
Sprachtext = string.Empty;
if (tools.GetLanguageText(Convert.ToInt32(f.Tag.ToString()), Language, ref Sprachtext) == true)
{
f.Text = Sprachtext;
}
}
}
}
catch (Exception)
{
//ignore and proceed
}
foreach (Control c in f.Controls)
{
if (c.Tag != null)
{
if (string.IsNullOrEmpty(c.Tag.ToString()) == false)
{
if (tools.IsNumeric(c.Tag.ToString()) == true)
{
Sprachtext = string.Empty;
if (tools.GetLanguageText(Convert.ToInt32(c.Tag.ToString()), Language, ref Sprachtext) == true)
{
c.Text = Sprachtext;
}
}
}
}
}
}
catch (Exception)
{
//ignore
}
}
如果有問題回答此問題,請告訴我。
此外,如果有什麼可以改善這個問題,請讓我知道。
var culture =「en-GB」; Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); – jannagy02