如何在Silverlight4項(xiàng)目中實(shí)現(xiàn)一個(gè)多語言功能?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
為宿遷等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及宿遷網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、宿遷網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!1:在項(xiàng)目中新建文件夾“Resouce”,然后再該文件夾下面新增資源文件“AppString.resx”,如果創(chuàng)建一個(gè)AppString.resx副本,把文件名改為對(duì)應(yīng)的語言名稱,
如AppString.en-US.resx。,并且把AppString.resx的訪問修飾符改為Public
2:打開AppString.resx的cs文件,查看類的訪問修飾符是否Public,如果不是,則改為Public。
3:打開App.xmal文件,添加以下代碼,目的是用于其它的頁面綁定字符內(nèi)容的資源文件。
4:然后再其它頁面就可以使用這個(gè)資源文件了,我這里用了三種語言
5:接下來就是語言切換了,我用的是本地存儲(chǔ)的方式來保存用戶選擇的語言,新建一個(gè)類來專門負(fù)責(zé)讀取當(dāng)前用戶選擇的語言。
復(fù)制代碼 代碼如下:
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)
{
}
}
}
}
一下是“切換”按鈕的代碼
復(fù)制代碼 代碼如下:
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");
}
6:最后是應(yīng)用程序啟動(dòng)的代碼,也就是讀取用戶保存的語言。在App.xmal.cs文件里,
復(fù)制代碼 代碼如下:
private void Application_Startup(object sender, StartupEventArgs e)
{
CultureInfo culture = Configure.CurrentCulture;
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
this.RootVisual = new MainPage();
}
關(guān)于如何在Silverlight4項(xiàng)目中實(shí)現(xiàn)一個(gè)多語言功能問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
文章標(biāo)題:如何在Silverlight4項(xiàng)目中實(shí)現(xiàn)一個(gè)多語言功能-創(chuàng)新互聯(lián)
路徑分享:http://www.rwnh.cn/article46/copshg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站改版、軟件開發(fā)、網(wǎng)站收錄、外貿(mào)建站、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容