I'm trying to add a DependencyProperty to a WPF custom control.
Everything is fine until I keep the code generate by the snippet propdp:
namespace CustomControl
{
public partial class MainControl
{
public string MyProperty
{
get { return (string)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(MainControl), new UIPropertyMetadata(0));
public MainControl()
{
this.InitializeComponent();
}
}
}
But as soon as I change the type from "int" to "string", I got a runtime error which tells "Impossible to create an instance of MainControl defined in assembly CustomControl etc....
Then I change back to type "int" and everything run again properly.
Does somebody have a clue to fix this mystery?