I want to refactor many similar controls that only differ in the value of a single property (besides positioning properties).
Imagine that I have an user control (let’s call it UC1) that have a Label. The Label.Content should be value + ":" where value is passed through a Property to the user control.
I could implement it by hand using the Initialized event, but it happens that in my case it isn’t a Label but a custom control (let’s call it UC2) which itself needs the property on its own Initialized event.
Somehow the UC2 Initialized runs before the UC1’s, and it throws an exception because the property value is not set yet.
How to solve this?
Maybe the problem is cause by calling
InitializeComponent()inside the user control when it shouldn’t.It may cause the
Initializedevent to be fired twice.