Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PropertyMetadata注册类型为“的从属财产”;System.Windows.Point“;?_C#_Dependency Properties_Createinstance - Fatal编程技术网

C# PropertyMetadata注册类型为“的从属财产”;System.Windows.Point“;?

C# PropertyMetadata注册类型为“的从属财产”;System.Windows.Point“;?,c#,dependency-properties,createinstance,C#,Dependency Properties,Createinstance,这是我的密码: public class ExoticPoint : DependencyObject { public Point PointValue { get { return (Point)GetValue(PointValueProperty); } set { SetValue(PointValueProperty, value); } } public static readonly DependencyPrope

这是我的密码:

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)
    {
    }
}
它可以编译,但当我想要创建我类型的实例时,它会崩溃,并出现以下错误:

{"Default value type does not match type of property 'PointValue'."}
所以我有点确定问题在于:

new PropertyMetadata(0)
但据我所知,PropertyMetadata应该可以工作,因为有一个以int为参数的点构造函数:


所以。。。有什么问题吗?

是的,您是对的。问题在于传递到
PropertyMetada
的对象。该参数将是属性的默认值,因此它必须与依赖属性的类型匹配

在您的情况下,
PointValue
类型是
Point
,因此您应该编写
新属性元数据(新点(0))


还有您的
说明
属性,它是
字符串
新的UIPropertyMetadata(“0”)
新的UIPropertyMetadata(“”
),具体取决于您的需要。

我尝试了新的PropertyMetadata(新的点(0)),但它崩溃了,所以我回来了。事实上,那是因为绳子的缘故,太浪费时间了…:(