这是我的代码:
public class ExoticPoint : DependencyObject
{
public Point PointValue
{
get { return (Point)GetValue(PointValueProperty); }
set { SetValue(PointValueProperty, value); }
}
public static readonly DependencyProperty PointValueProperty =
DependencyProperty.Register("PointValue", typeof(Point), typeof(ExoticPoint), new PropertyMetadata(0));
public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(ExoticPoint), new UIPropertyMetadata(0));
public ExoticPoint()
{
}
public ExoticPoint (string objectName)
: base(objectName)
{
}
}
它可以编译,但是当我想创建我的类型的 CreateInstance 时,它会崩溃并出现以下错误:
{"Default value type does not match type of property 'PointValue'."}
所以我有点确定问题是:
new PropertyMetadata(0)
但据我了解 PropertyMetadata 它应该可以工作,因为有一个以 int 作为参数的 Point 构造函数:http: //msdn.microsoft.com/en-us/library/bf1b4f2b.aspx
所以……怎么了?