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
        }
  • 相关阅读:
    PHP7 网络编程(六)Socket和IO多路复用【待】
    PHP7 网络编程(五)进程间通信【待】
    PHP7 网络编程(四)signal信号【待】
    PHP7 网络编程(三)孤儿进程与僵尸进程
    PHP7 网络编程(二)daemon守护进程
    PHP7 网络编程(一)多进程初探
    为什么要用Rust取代C/C ++重写Python底层?
    Modern Self-Service Data Platforms
    一文读懂量化系统接入及相关平台
    rust asynchronous io:从 mio 到 coroutine
  • 原文地址:https://www.cnblogs.com/visi/p/1766599.html
Copyright © 2011-2022 走看看