zoukankan      html  css  js  c++  java
  • silverlight 国际化的一种实现方法

    大致思路如下:定义一个语言转换器并实现INotifyPropertyChanged接口,在转换器实现的时候调用资源文件,通过PropertyChangedEventHandler通知UI从而实现多语言。

    代码
        public class LanguageConverter : IValueConverter, INotifyPropertyChanged
        {
            #region IValueConverter
            
    /// Converter to go find a string based on the UI culture
            public object Convert(object value, Type targetType,
                                  
    object parameter, CultureInfo culture)
            {
                
    if ((value == null|| !(value is string))
                    
    return "set Binding Path/Source!";

                
    return StringResourceManager.GetString(
                        (
    string)parameter, System.Threading.Thread.CurrentThread.CurrentUICulture);
              }

            
    public object ConvertBack(object value, Type targetType,
                
    object parameter, CultureInfo culture)
            {
                
    throw new NotImplementedException("No reason to do this.");
            }

            
    #endregion IValueConverter

            
    #region INotifyPropertyChanged Members

            
    public event PropertyChangedEventHandler PropertyChanged;

            
    /// <summary>
            
    /// Change the culture for the application.
            
    /// </summary>
            
    /// <param name="culture">Full culture name</param>
            public void ChangeCulture(string culture)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture 
    =
                    
    new System.Globalization.CultureInfo(culture);
                System.Threading.Thread.CurrentThread.CurrentCulture 
    =
                        System.Threading.Thread.CurrentThread.CurrentUICulture;
                DefaultResource.Culture 
    = System.Threading.Thread.CurrentThread.CurrentUICulture;

                
    // notify that the culture has changed
                PropertyChangedEventHandler handler = PropertyChanged;

                
    if (handler != null)
                    handler(
    thisnew PropertyChangedEventArgs("AString"));
            }
        public static string AString { get { return "AString"; } }

            
    #endregion
        }
  • 相关阅读:
    Delphi开发组件
    WPF界面开发.NET环境该如何配置?不知道VS版本支持的看过来
    Map控件是如何支持矢量切片的?DevExpress WPF界面开发者必看!
    数据可视化新方式,SankeyDiagramControl类的使用你不能错过!(Part 1)
    VCL界面开发工具!DevExpress VCL v20.1.7全新出发
    如何使用自动生成的序列创建3D图表?DevExpress WPF有妙招(Part 3)
    如何使用Kendo UI在Vue.js中轻松构建UI组件?
    php结合redis实现高并发下的抢购、秒杀功能
    书写高质量SQL的30条建议
    php 通过openresty搭载负载均衡
  • 原文地址:https://www.cnblogs.com/visi/p/1766599.html
Copyright © 2011-2022 走看看