【发布时间】:2009-03-23 13:33:34
【问题描述】:
例外:
无法将属性“文本”中的值转换为类型的对象 '系统.字符串'。无法投射物体 要键入的“MyApp.Foo”类型 'System.String'。
XAML:
<Window.Resources>
<my:Foo x:Key="foo"></my:Foo>
</Window.Resources>
<TextBox Text="{DynamicResource foo}"></TextBox>
C#
[TypeConverter(typeof(FooConverter))]
public class Foo
{
public Foo()
{}
}
public class FooConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return true;
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return "Foo";
}
}
怎么了?
【问题讨论】:
标签: wpf resources typeconverter