Reputation: 6547
I'm creating a custom control deriving from TextBox
. I am trying to override the default value of it's Height
property, but I keep getting an error that the types don't match.
Metadata override and base metadata must be of the same type or derived type.
on MSDN it states that Height
property is of type System.Double
.
I have tried the following:
1) converting to double
HeightProperty.OverrideMetadata(typeof(SuggestionTextBox), new UIPropertyMetadata(Convert.ToDouble(200)));
and
HeightProperty.OverrideMetadata(typeof(SuggestionTextBox), new UIPropertyMetadata((double)200));
2) Tried to figure out the the default value by
HeightProperty.DefaultMetadata.DefaultValue
Which returns Double.NaN
EDIT: I'm doing this in the static constructor of the control as shown in the example on MSDN
Any Idea how I can override it's default values?
Upvotes: 2
Views: 827
Reputation: 18578
The problem is not with the Type of Default value but with the Type of PropertyMetaData
,
Instead of UIPropertyMetadata
you will have to use FrameworkPropertyMetadata
as this is what HeightProperty
metadata type is.
HeightProperty.OverrideMetadata(typeof(SuggestionTextBox), new FrameworkPropertyMetadata(Convert.ToDouble(200)));
Upvotes: 5