Silverlight中文显示

当前版本Silverlight还不能直接支持中文显示,但我们可以通过变通的方法让其显示中文,一般可通过以下二种方案实现:

1、使用Glyphs
XAML:

1 < Glyphs Fill = " Red "  UnicodeString = " 中文显示 "
2   FontUri = " http://localhost/ChineseFont/Fonts/649C70ED-5A7E-7277-6038-1A0DBB6BDF08.odttf "
3   FontRenderingEmSize = " 30 "  Canvas.Top = " 120 " />

2、使用TextBlock
XAML:
1 < TextBlock  TextWrapping ="Wrap"  x:Name ="txtMsgList"  Canvas.ZIndex ="10" />
JS:
 1  handleLoad:  function (control, userContext, rootElement) 
 2  {
 3       this .control  =  control;
 4       this .rootElement = rootElement; 
 5       // 下载中文字体
 6       var  fontDownloader  =  control.CreateObject('downloader');
 7      fontDownloader.addEventListener('completed',  this .createDelegate( this this .onFontsDownloaded));
 8      fontDownloader.open('GET', '.. / Silverlight / Fonts / simhei.ttf'); // 此处如果用.zip,则会出错,不知如何解决
 9      fontDownloader.send();
10  },
11  onFontsDownloaded:  function (sender, eventArgs) {
12       var  commentText  =  sender.findName('txtMsgList');
13      commentText.setFontSource(sender);
14      commentText.fontFamily  =  'SimHei'; // 设置TextBlock字体为SimHei
15  },

更多中文处理,可参考:
http://www.microsoft.com/taiwan/msdn/columns/huang_jhong_cheng/Silverlight_cht_solutions.htm


你可能感兴趣的:(silverlight)