Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C中的枚举使用本地化值绑定下拉列表#_C#_.net_Enums_Dropdownbox - Fatal编程技术网

C# 使用C中的枚举使用本地化值绑定下拉列表#

C# 使用C中的枚举使用本地化值绑定下拉列表#,c#,.net,enums,dropdownbox,C#,.net,Enums,Dropdownbox,使用C#中的枚举使用本地化值绑定下拉列表 我对所有的语言都有价值。所以我不需要从其他地方取。 我可以用不同的语言将所有值写入resx文件。但我不确定它是如何工作的 我正在使用C#windows窗体。框架3.5私有静态资源管理器\u resources=新资源管理器(“MyClass.myResources”, private static ResourceManager _resources = new ResourceManager("MyClass.myResources", Sys

使用C#中的枚举使用本地化值绑定下拉列表

我对所有的语言都有价值。所以我不需要从其他地方取。 我可以用不同的语言将所有值写入resx文件。但我不确定它是如何工作的

我正在使用C#windows窗体。框架3.5

私有静态资源管理器\u resources=新资源管理器(“MyClass.myResources”,
private static ResourceManager _resources = new ResourceManager("MyClass.myResources",
    System.Reflection.Assembly.GetExecutingAssembly());

public static IEnumerable<string> GetLocalizedNames(this IEnumerable enumValues)
{
    foreach(var e in enumValues)
    {
        string localizedDescription = _resources.GetString(String.Format("{0}.{1}", e.GetType(), e));
        if(String.IsNullOrEmpty(localizedDescription))
        {
            yield return e.ToString();
        }
        else
        {
            yield return localizedDescription;
        }
    }
}
System.Reflection.Assembly.getExecutionGassembly()); 公共静态IEnumerable GetLocalizedNames(此IEnumerable enumValues) { foreach(枚举值中的变量e) { string localizedDescription=_resources.GetString(string.Format(“{0}.{1}”,e.GetType(),e)); if(String.IsNullOrEmpty(localizedDescription)) { 收益率收益率e.ToString(); } 其他的 { 收益率本地化描述; } } }
我使用了以下代码,对我来说效果很好

using System.Globalization;
using System.ComponentModel;
using System.Threading;

Thread.CurrentThread.CurrentUICulture = new CultureInfo(DDLLang.SelectedValue);
ComponentResourceManager resource = new ComponentResourceManager(typeof(Default));
resource.ApplyResources(LblName, "LblName");
LblName.ID = "LblName";
Response.Write(resource.GetString("strMsg",CultureInfo.CurrentUICulture)??resource.GetString("strMsg"));

Thread.CurrentThread.CurrentUICulture = new CultureInfo(DDLLang.SelectedValue);
ComponentResourceManager resource = new ComponentResourceManager(typeof(Default));
resource.ApplyResources(LblName, "LblName");
LblName.ID = "LblName";
Response.Write(resource.GetString("strMsg",CultureInfo.CurrentUICulture)??resource.GetString("strMsg"));

Thread.CurrentThread.CurrentUICulture = new CultureInfo(DDLLang.SelectedValue);
ComponentResourceManager resource = new ComponentResourceManager(typeof(Default));
resource.ApplyResources(LblName, "LblName");
LblName.ID = "LblName";
Response.Write(resource.GetString("strMsg",CultureInfo.CurrentUICulture)??resource.GetString("strMsg"));
在上面的代码中,LblName是一个标签,StrMsg是一个简单的字符串

在资源文件中,我将这样写:

名称值


Lbl.Namelabelname


StrMsganycustom msg

您在这里使用的是什么UI框架?WPF、asp.net、winforms等等……是的。你试过什么?在.NET framework中的大多数UI技术中,有时使用可用的编辑器,这并不是说没有用于本地化的挂钩。