I have a stackpanel with some usercontrols that are added or removed during runtime. These elements have an index that i assign to them when i new them, I need to keep these
If you want to do that you need to make sure that the Parent is null and also that your index into your panel is not in use.
If you just swap it into a temp variable, it's still the same reference.
Use the Visual Tree Helper in order to disconnter or move your UIElement.