您的位置:首页 > 其它

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

2014-06-30 11:05 148 查看
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 不支持从字符串进行转换。这个问题到目前为止还没有解决。但是程序是可正常运行的。没有运行问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  WPF 解析器 xmal
相关文章推荐