WPF类型转换

类型转换类:

  public class StringToHumanTypeConverter:TypeConverter
    {
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                Human h = new Human();
                h.Name = value as string;
                return h;
            }
            return base.ConvertFrom(context, culture, value);
        }
    }

 

粘贴特性类,实现类型转换

  [TypeConverter(typeof(StringToHumanTypeConverter))]
    public class Human
    {
        public string Name { get; set; }
        public Human Child { get; set; }
    }

 

posted on 2023-05-17 00:14  drewwestlhq  阅读(9)  评论(0编辑  收藏  举报

导航