Question

Hey embarrassingly enough I ran into the error stated in the title. As many others have sought to find a solution online, but I was not able to do so.

Okay so my issue, is that I have an ObservableCollection of my elements which is used in an Itemscontrol. I want to create a new element of one of the elements in the ObservableCollection. Because of the trouble with working with ObservableCollection I created a serializing and Deserializing of the specific object. like this>

IsolatedStorage.SerializeSElement("saveString", saveElement);
IsolatedStorage.DeSerializeSElement("saveString", loadElement);

Which I than hoped gave me a completely new element. But I still have the same element. How do I solve the issue if say my class looks like>

public class myElement(){
    int posx;
    int posy;
    double id;
    bool isMoveable;
}

But there is still the error, is there way to solve this error?

Code

 private Geometry createGeometry(SViewModel sModelRec)
        {//TEST

            sModel = sModelRec.Gear;
            sModelRec = null;
            //new Path.Combine(DecorationOnShield[i].Gear.Path,"");
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure testPathFigure = new PathFigure();

            System.Windows.Shapes.Path pathTesting = new System.Windows.Shapes.Path();
            var b = new System.Windows.Data.Binding
            {
                Source = sModel.Path
            };

            System.Windows.Data.BindingOperations.SetBinding(pathTesting, System.Windows.Shapes.Path.DataProperty, b);
            pathTesting.Width = sModel.Width;
            pathTesting.Height = sModel.Height;

            Geometry geometry = pathTesting.Data;
            return geometry;
        }

So when I return the element and add it to the GeometryGroup I get the error.

Was it helpful?

Solution

You are trying to Add a Control and that Control already exists in your VisualTree. The solution is simple

You have Source Parent Container = The control in witch resides the element you want to add to the other container Target Parent Container = The control in witch you want to add your element.

To solve your problem just remove the element from the Source Parent Container and then add it to your Target Parent Container

Note: to have an answer more specific to your situation you must post your view or the lines where the error is getting thrown

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top