The default value type does not match the property type.

I have this class

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

And this custrom control

 public partial class ToothUI : UserControl { public ToothUI() { InitializeComponent(); } public Tooth Tooth { get { return (Tooth)GetValue(ToothProperty); } set { SetValue(ToothProperty, value); NombrePieza.Text = value.Id.Replace("_",String.Empty); } } public static readonly DependencyProperty ToothProperty = DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI), new PropertyMetadata(0)); } 

My problem is after adding the tooth dependency property , this error occurs

The default value type does not match the property type.

What does this error mean? What is the current way to install this DP

+46
c # wpf wpf-controls
Dec 05 '13 at 11:26
source share
2 answers

Default value for DP does not match your type.

Edit

 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 the default value for DP:

 public static readonly DependencyProperty ToothProperty = DependencyProperty.Register("Tooth", typeof(Tooth), typeof(ToothUI)); 
+93
Dec 05 '13 at 11:27
source share

I came here for the title of the question, but my type was the decimal default, and I decided with this 0.0M https://msdn.microsoft.com/en-us/library/83fhsxwc.aspx

+2
03 Oct '16 at 22:14
source share



All Articles