Wednesday, September 1, 2010

DP_DefaultValueTypeDoesNotMatchPropertyType Error

If you create a Silverlight (and probably WPF) usercontrol and get a DP_DefaultValueTypeDoesNotMatchPropertyType error when rendering the control, make sure you are setting the right kind of default value in the .Register method.

The following code generated that error.

public static readonly DependencyProperty HourFillProperty = DependencyProperty.Register(
"HourFill", typeof(int), typeof(ucScheduleHour),
new PropertyMetadata(null,
new PropertyChangedCallback(ChangeValue)));


My value was an int so I needed to change null to a 0,


public static readonly DependencyProperty HourFillProperty = DependencyProperty.Register(
"HourFill", typeof(int), typeof(ucScheduleHour),
new PropertyMetadata(0,
new PropertyChangedCallback(ChangeValue)));

No comments: