Silverlight如何支持多语言
来源:互联网 发布:淘宝上有没有微信号卖 编辑:程序博客网 时间:2024/05/21 22:55
利用资源文件(Resources File)使SilverLight支持多语言。
1. 创建一个SilverLight应用程序, MultiLanguageDemo。
2. 添加一个资源文件,命名为ApplicationStrings.resx。
3. 添加String类型的资源,这里添加 UsernameString:User Name。设置Access Modeifer为Public。
4. 为了让程序可以支持中文,再添加一个资源文件:ApplicationStrings.zh-CN.resx。(一定要保证.zh之前的名称与之前的resx一致才行,否则不会读取该文件)这里的zh-CN就是语言区域性名称。关于这个名称可以查阅MSDN。最好是使用zh-Hans这样才能在XP以及WIN7系统下都能正常显示。
5. 为这个资源文件添加同样的资源,只是这次是用中文写的。UsernameString:姓 名。确保Access Modeifer为No code generation。
6. 使用资源来显示文本内容。这里可以通过代码实现,也可以做一个ResourcesWrapper的类,用于直接Binding。这里是用Binding的方式。
using System;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace MultiLanguageDemo{ public class ResourcesWrapper { private static MultiLanguageDemo.ApplicationStrings app = new ApplicationStrings(); public MultiLanguageDemo.ApplicationStrings App { get { return app; } } }}
在MainPage:
<UserControl x:Class="MultiLanguageDemo.MainPage" 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:MultiLanguageDemo" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <local:ResourcesWrapper x:Key="ResourcesWrapper"/> </Grid.Resources> <TextBlock Text="{Binding Source={StaticResource ResourcesWrapper},Path=App.UserNameString}"/> </Grid></UserControl>
7. 为了让Silverlight在XAP文件中加入支持的语言资源,我们还需要编辑一下.csproj文件。Unload SilverLight 工程,右键编辑这个文件,在<SupportedCultures>节点中,添加支持的语言,之间用分号隔开。例如:
<SupportedCultures>en-US;zh-CN;zh-Hans</SupportedCultures>
8. 好了,让我们重新加载这个工程,并且编译一下。现在可以看到,在Debug目录下,多出来一个zh-CN的目录,这便是中文支持的语言包了。为了确保XAP中也包含这个文件,可以将XAP用Zip解开,会看到同样包含这个目录。
9. 让我们试一下这个可不可行,直接运行。结果发现,显示出来的还是英文。哦,因为默认UI是显示英文的,修改App.xaml.cs,将UI语言和区域语言一致,当然,这里也可以直接指定使用其他语言。
private void Application_Startup(object sender, StartupEventArgs e) { Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture; this.RootVisual = new MainPage(); }
好了,这样我们就可以让我们的SilverLight程序支持多国语言了。
源代码: http://download.csdn.net/detail/eric_k1m/5811615
- Silverlight如何支持多语言
- Silverlight中的多语言支持中几个特殊之处
- 如何配置支持Silverlight的Web服务器
- 如何让自己的IIS支持Silverlight
- 如何让javascript也支持多语言
- MVC:如何设计多语言支持
- thinkphp3.2.2如何支持多语言切换
- Silverlight实现多语言
- Silverlight中 多语言
- 如何制作多语言dll支持应用程序多语言版本
- 多语言支持如何显示各种语言的名称
- Silverlight本地化与多语言
- Silverlight多语言的实现
- 如何让你的iPhone程序支持多语言环境
- 如何让你的iPhone程序支持多语言环境
- 如何让你的iPhone程序支持多语言环境
- 如何让你的iPhone程序支持多语言环境
- 如何让Cocoa程序支持多语言本地化处理
- plsql developer 使用技巧设置
- android电子书
- 【水】UVA10167birthday cake
- 柔性数组
- android 基础知识 七
- Silverlight如何支持多语言
- OpenCV中对Mat里面depth,dims,channels,step,data,elemSize和数据地址计算的理解
- sqlload的用法
- Android中自定义seekbar样式
- 检测笔记本电脑的主板,cpu,硬盘的温度
- MFC.UI线程问题
- 手把手教你如何识别钓鱼网站
- Ajax中使用Json传递数据
- Android_SharedPreferences用户偏好设置