WPF UI多国语言的实现

来源:互联网 发布:red5 oflademo 源码 编辑:程序博客网 时间:2024/05/16 00:52

1.安装Microsoft Expression+VS2008.

2.导入数据源。帮定到各个控件。这时你只是实现了一国语言的帮定,如果你要做多国语言,需要做到动态帮定。

3.动态帮定数据源,

public  void XmlSetSource()
 {
  string szPath=System.Environment.CurrentDirectory;
   XmlDataProvider xmlData = (XmlDataProvider)(FindResource("hpstring"));
  szPath+="//Lang_UI//"+Configure.g_szLangFolder+"//hp_strings.xml";
         xmlData.Source = new Uri(szPath, UriKind.RelativeOrAbsolute);

 }

至此多国语言的完现就完成了,是不是很简单呢。

4.读ini文件,在有的时候我们可能需要读写ini文件,要注意的是ini文件应该保存为UTF-8的文件,不然有些语系,读进来会是乱码。读进来还要做一下转换。

 [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
     public void GetNativeFunctionName(string szFuncName, ref string szDescName)
    {
             string szPath = System.Environment.CurrentDirectory;
        szPath += "//Lang_UI//" + Configure.g_szLangFolder + "//BtnList.ini";
               Byte[] szBuffer1 = new Byte[65535];
        int bufLen = GetPrivateProfileString(Configure.g_szLangFolder, szFuncName, "",szBuffer1, 256/*szBuffer.GetUpperBound(0)*/, szPath);
        Byte[] szBuffer = new Byte[bufLen];
         bufLen = GetPrivateProfileString(Configure.g_szLangFolder, szFuncName, "", szBuffer, 256/*szBuffer.GetUpperBound(0)*/, szPath);
            string s = Encoding.UTF8.GetString(szBuffer);
              s = s.Trim();
           szDescName = s;

  

    }

原创粉丝点击