xmal 解析器没有办法解析类的TypeConverter.代码如下
页面代码:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:codes="clr-namespace:WpfApplication_xmln.Codes" Title="ConvertWindow" Height="300" Width="300">
后台代码:
[TypeConverterAttribute(typeof(StringToHumanTypeConvert))]
class Human
{
public string Name { get; set; }
public Human Child { get; set; }
}
class StringToHumanTypeConvert : TypeConverter// using System.System.ComponentModel;
{
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value != null)
{
Human h = new Human();
h.Name = value.ToString();
return h;
}
return base.ConvertFrom(context, culture, value);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Human h = this.FindResource("scHuman") as Human;
MessageBox.Show(h.Child.Name);
}
错误1“Human”的 TypeConverter 不支持从字符串进行转换。这个问题到目前为止还没有解决。但是程序是可正常运行的。没有运行问题。