多语言直接resource里面定义多个语言文件 根据选择语言不同加载不同resource文件不就行了
然后用的地方findresource(“key”)不就行了么?

解决方案 »

  1.   


    在别的地方是可以的 但是findresource(“key”)在替换上面的文字的时候会报错,要求是常量。
      

  2.   

    什么叫改变后面的value 后台的值不会改变???
    另外我看那个方法只是在玩,根本不能用在实际项目中,因为这样的处理没有任何实际意义。
      

  3.   

    利用TypeDescriptor.AddProvider方法,添加运行时的TypeDescriptionProvider,下面是对IDictionary<string, object>类型定义的TypeDescriptionProvider,参照这个例子,给你的类型定义自己的TypeDescriptionProvider,添加多语言的CategoryAttribute值。    public class DynamicDescriptionProvider : TypeDescriptionProvider
        {
            public DynamicDescriptionProvider() : base() { }        public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
            {
                return new DynamicTypeDescriptor(objectType, instance);
            }
        }
        public class DynamicTypeDescriptor : CustomTypeDescriptor
        {
            public DynamicTypeDescriptor(Type objectType, object instance)
                : base()
            {
                if (instance != null)
                {
                    var tmp = (IDictionary<string, object>)instance;
                    var names = tmp.Keys;
                    foreach (var name in names)
                    {
                        customFields.Add(new DynamicPropertyDescriptor(name, instance));
                    }
                }
            }
            List<PropertyDescriptor> customFields = new List<PropertyDescriptor>();
            public override PropertyDescriptorCollection GetProperties()
            {
                return new PropertyDescriptorCollection(customFields.ToArray());
            }        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
            {
                return new PropertyDescriptorCollection(customFields.ToArray());
            }
        }
        public class DynamicPropertyDescriptor : PropertyDescriptor
        {
            Type propertyType = typeof(object);
            public DynamicPropertyDescriptor(string name, object instance)
                : base(name, null)
            {
                var obj = (IDictionary<string, object>)instance;
                if (obj[name] != null)
                    propertyType = obj[name].GetType();
            }        public override bool CanResetValue(object component)
            {
                return false;
            }        public override Type ComponentType
            {
                get
                {
                    return typeof(FastExpando);
                }
            }        public override object GetValue(object component)
            {
                IDictionary<string, object> obj = (IDictionary<string, object>)component;
                return obj[Name];
            }        public override bool IsReadOnly
            {
                get
                {
                    return false;
                }
            }        public override Type PropertyType
            {
                get
                {
                    return propertyType;
                }
            }        public override void ResetValue(object component)
            {
                throw new NotImplementedException();
            }        public override void SetValue(object component, object value)
            {
                IDictionary<string, object> obj = (IDictionary<string, object>)component;
                obj[Name] = value;
            }        public override bool ShouldSerializeValue(object component)
            {
                return false;
            }
        }
      

  4.   


    我的问题解决了,参考这个例子
    http://www.codeproject.com/Articles/4341/Globalized-Property-Grid-Revisited
    可以实现语言的动态切换,但是CategoryName无法改变。查了MSDN文件中的CategoryAttribute.GetLocalizedString Method,说" Category 属性第一次被存取时会呼叫这个方法来查阅指定分类的当地语系化名称。",就是说GetLocalizedString Method只能执行一次。不知道能不能强制改变。
    不行的话就加个重启后生效。。
      

  5.   

    哈哈,我正好路过,楼主问题解决了吧。
    在 PropertyDescriptor   重写 Catagory属性,即可达到 目录多语言的 热切换。