ContentControl with ContentProperty missing TypeConverter-Collection of common programming errors
I’m trying to create a ContentControl that displays numbers and allows user to specify values as it’s content 123. I’ve created a very simple class with ContentProperty(“Value”) and a style. However when i try to compile, i get the following error:”The Element type ‘WPFPropertyGrid.NumericInput’ does not have an associated TypeConverter to parse the string ‘123’”I’ve read the help for the ContentProperty and in there it says:
“If the associated property of a ContentPropertyAttribute is not of type string or object, a type converter will be called at runtime. If a type converter cannot be found at runtime, an exception is thrown.”
I’ve tried marking my Value property with a TypeConverter(typeof(DoubleConverter)) but this didn’t help.Does anyone have any suggestions?
[ContentProperty(“Value”)] public class NumericInput : ContentControl { public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(“Value”, typeof(double), typeof(NumericInput),
new FrameworkPropertyMetadata(0.0, new PropertyChangedCallback(OnValueChanged)));
private static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { NumericInput numericInput = obj as NumericInput;
}
[TypeConverter(typeof(DoubleConverter))] public double Value { get { return (double)this.GetValue(ValueProperty); } set { this.SetValue(ValueProperty, value); }
}
public NumericInput() { DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericInput), new FrameworkPropertyMetadata(typeof(NumericInput))); } }—————-
————————-
123