关于.net compact frame 中的 TypeConverter
he717 2009-09-02 09:34:40 看了网上有很多人写关于TypeConverter类的,但是,在CF中TypeConverter类只有一个空壳,没有虚函数,不知道该如何用?我试着把函数都填写进去了,但不能加override,因为TypeConverter没有函数,但是不起效果。求大侠帮忙。。代码如下:
public class MyConverter : TypeConverter
{
public bool CanConvertFrom(Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return false;
}
public bool CanConvertTo(Type destinationType)
{
if (destinationType == typeof(MyPoint3D))
return true;
else
return false;
}
public object ConvertTo(System.Globalization.CultureInfo culture, object value, Type destinationType)
{
return value.ToString();
}
public object ConvertFrom(System.Globalization.CultureInfo culture, object value)
{
TouchPlotAxis axis = new TouchPlotAxis();
axis.max = 10;
axis.min = -10;
return axis;
}
}
public struct MyPoint3D
{
public int x;
public int y;
public int z;
}
在DesignTimeAttribute.xmta文件中是这样描述的
<Class Name="MyComponent.MyPoint3D">
<TypeConverter>
typeof(MyConverter)
</TypeConverter>
</Class>