"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; } }