1:在项目中新建文件夹“Resouce”,然后再该文件夹下面新增资源文件“AppString.resx”,如果创建一个AppString.resx副本,把文件名改为对应的语言名称,
public class Configure
{
static System.Globalization.CultureInfo currentCulture;
public static System.Globalization.CultureInfo CurrentCulture
{
get
{
if (currentCulture == null)
{
try
{
System.IO.IsolatedStorage.IsolatedStorageSettings appSetting = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
if (appSetting.Contains("language"))
{
currentCulture = new System.Globalization.CultureInfo((string)appSetting["language"]);
}
}
catch (Exception e)
{
}
}
if (currentCulture == null)
{
currentCulture = new System.Globalization.CultureInfo("en-us");
}
return currentCulture;
}
set
{
currentCulture = value;
System.Threading.Thread.CurrentThread.CurrentCulture = currentCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = currentCulture;
try
{
System.IO.IsolatedStorage.IsolatedStorageSettings appSetting = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
if (appSetting.Contains("language"))
{
appSetting["language"] = currentCulture.Name;
appSetting.Save();
}
else
{
appSetting.Add("language", currentCulture.Name);
}
}
catch (Exception e)
{
}
}
}
}
private void button3_Click(object sender, RoutedEventArgs e)
{
Configure.CurrentCulture = new CultureInfo(comboBox1.SelectionBoxItem.ToString());
//if (Configure.CurrentCulture.Name == "zh-CN")
//{
// Configure.CurrentCulture = new CultureInfo("en-US");
//}
//else
// Configure.CurrentCulture = new CultureInfo("zh-CN");
}
private void Application_Startup(object sender, StartupEventArgs e)
{
CultureInfo culture = Configure.CurrentCulture;
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
this.RootVisual = new MainPage();
}