WPF ---- ​xmal 解析器没有办法解析类的TypeConverter

2016-08-20 10:39:24来源:http://6772017.blog.51cto.com/6762017/1432317作者:neeky51人点击


xmal 解析器没有办法解析类的TypeConverter.代码如下

页面代码:

<Window x:Class="WpfApplication_xmln.Windows.ConvertWindow"

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

<Window.Resources>

<codes:Human x:Key="scHuman" Name="NiNi" Child="HeHe"></codes:Human>

</Window.Resources>

<Grid>

<Button Margin="50,50,50,50" Click="Button_Click" Content="this is the button" Background="Violet"></Button>

</Grid>

</Window>

后台代码:

[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 不支持从字符串进行转换。这个问题到目前为止还没有解决。但是程序是可正常运行的。没有运行问题。


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台