The default value type does not match the type of the property

前端 未结 2 2012
轮回少年
轮回少年 2020-12-25 09:40

I have this class

public class Tooth
{
    public string Id {get;set;}
}

And this custrom control

public partial class To         


        
2条回答
  •  不思量自难忘°
    2020-12-25 09:52

    Default value for DP does not match your type.

    Change

    public static readonly DependencyProperty ToothProperty =
            DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
                                             new PropertyMetadata(0));
    

    to

    public static readonly DependencyProperty ToothProperty =
            DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI),
                                          new PropertyMetadata(default(Tooth)));
    

    Or simply omit setting default value for your DP:

    public static readonly DependencyProperty ToothProperty =
            DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI));
    

提交回复
热议问题