Copyright © wp7 2011 . Powered by
青藤园
Courtesy of Open Web Design
& Hotels - Dubai
WP7如何实现多语言支持
实现目标:1.多语言实时切换
2.使用系统自带的多语言机制
3.支持xaml绑定
实现方法:
Step1. 创建语言文件lang.resx
Step2. 创建多语言文件lang.resx.zh-cn
Step3.右键卸载项目,并编辑。
在 <SupportedCultures> zh-cn </SupportedCultures> 中添加
Step4.创建langhelper辅助类
public class langhelper:INotifyPropertyChanged
{
public string this[string resourceName]
{
get
{
return resource.lang.ResourceManager.GetString(resourceName);
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void UpdateBindings()
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Item[]"));
}
}Step5.在mainviewmodel.cs 中添加///<summary>
/// 语言资源访问器(可绑定)
///</summary>
public langhelper lang { get; private set; }Step6.确定mainpage.xaml.cs中存在 DataContext = App.ViewModel;Step7.确定app.xaml.cs中存在
private static MainViewModel viewModel = null;
/// <summary>
/// A static ViewModel used by the views to bind against.
/// </summary>
/// <returns>The MainViewModel object.</returns>
public static MainViewModel ViewModel
{
get
{
// Delay creation of the view model until necessary
if (viewModel == null)
viewModel = new MainViewModel();
return viewModel;
}
}Usage:{Binding lang[appbar_search]}
//其中appbar_search就是你在多语言resx文件中添加的字符串Switch:CultureInfo info = new CultureInfo("zh-cn");//en-us;.....
Thread.CurrentThread.CurrentCulture = info;
Thread.CurrentThread.CurrentUICulture = info;原文链接:http://www.cnblogs.com/sailing/archive/2011/11/13/2247104.html
标签:
wp7 多语言
Posted by
wp7_developer @
2011-11-13 23:16:42
阅读(432)
评论(0)
上一篇:windows phone下实现一个比较酷的界面切换
下一篇:Windows Phone 7 开发之项目模板
上一篇:windows phone下实现一个比较酷的界面切换
下一篇:Windows Phone 7 开发之项目模板
Feedback
你还可以输入600/600个字符
发表评论