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
The answer above is correct, but if you can not change your stackpanel (if you have not enough time, or have written many codes related to the stackpanel) try this:
note: the code is working, Remove function removes the control from StackPanel item's (from the tree) but the control is already on the memory so that the control is able to inserting in any StackPanel or same of it.