所谓的潇洒

导航

"Human" 的TypeConvert不支持从字符串进行转换

程序能正常运行,但是xaml报错,设计器显示不出来,重写CanConvertFrom解决,代码如下

    public class StringToHumanTypeConvert:TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return sourceType == typeof(string);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string name = value.ToString();
            Human child = new Human();
            child.Name = name;
            return child;
        }
    }

  

posted on 2021-09-25 23:08  所谓的潇洒  阅读(466)  评论(0编辑  收藏  举报