Getting "<Property Name> was already registered by "<Control Name>" error in WPF
What's happening is the Dependency Property is getting Registered multiple times under the same name and owner. Dependency Properties are intended to have a single owner, and should be statically instanced. If you don't statically instance them, an attempt will be made to register them for each instance of the control.
Make your DependencyProperty declaration static. Change it from:
public DependencyProperty SomeStringValueProperty =
DependencyProperty.Register("SomeStringValue",
typeof(string),
typeof(ExampleUserControl));
To:
public static DependencyProperty SomeStringValueProperty =
DependencyProperty.Register("SomeStringValue",
typeof(string),
typeof(ExampleUserControl));
I did a cut and paste between two controls for the dependency property and forgot to change the registered class away from the first control on the second. Hence duplication.
public static readonly DependencyProperty CurrentBatchProperty =
DependencyProperty.Register(
"CurrentBatch",
typeof(Batch),
typeof({--- Must be same as encompassing class --}), // Error if not set properly.
new PropertyMetadata(null, OnCurrentBatchPropertyChanged));
For upon pasting the code, my original control was then registering it in two different controls and it got the squiggly line (on the placement page) and the error.
My error message of this type was caused by registering a dependency property with a base class
i.e this
public static readonly DependencyProperty WorkerStateProperty =
DependencyProperty.Register("WorkerState", typeof(State), typeof(Control),
new FrameworkPropertyMetadata(State.Stopped, new PropertyChangedCallback(OnWorkerStateChanged)));
instead of this
public static readonly DependencyProperty WorkerStateProperty =
DependencyProperty.Register("WorkerState", typeof(State), typeof(WorkerControl),
new FrameworkPropertyMetadata(State.Stopped, new PropertyChangedCallback(OnWorkerStateChanged)));
where my WorkerControl class derived from Control