Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8090885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:52:29+00:00 2026-06-05T19:52:29+00:00

I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();

  • 0

I have a little problem.

This is my code:

stackPanelShapesContainer = new StackPanel();
InitializeStackPanle();

var gotFocusStackPanle =(StackPanel) canvas.Children[gotFocusStackPanelIndex];

foreach (UIElement child in gotFocusStackPanle.Children)
{
     UIElement uiElement = child;
     stackPanelShapesContainer.Children.Add(uiElement);
}

In the line 9 of above code, I get following error –

Specified element is already the logical child of another element.
Disconnect it first.

How can I fix it? Any solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:52:30+00:00Added an answer on June 5, 2026 at 7:52 pm

    I hope the reason for error will be clear to you from comments and other posts; I assume that you want to create a copy of control present in one panel into another, if this is the case then you will have to first clone the control and then add it to new panel.

    You can clone a control by first serializing it using XamlWriter and then create a new control by deserializing it using XamlReader, something like this –

    foreach (UIElement child in gotFocusStackPanle.Children)  
    {  
         string childXaml = XamlWriter.Save(child);
    
        //Load it into a new object:
        StringReader stringReader = new StringReader(childXaml);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        UIElement clonedChild = (UIElement)XamlReader.Load(xmlReader);
    
        stackPanelShapesContainer.Children.Add(clonedChild);  
    }  
    

    But, you may find yourself applying workarounds to make it work as there are some limitations in using XamlWriter.Save (like with bindings) – Serialization Limitations of XamlWriter.Save

    Here are some other approaches for serialization –

    An XAML Serializer Preserving Bindings

    XamlWriter and Bindings Serialization

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a little problem with this code: UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
I have a little problem with ~ in my paths. This code example creates
I have a little problem with my simple login system. this is the code
I have this little problem, that I cannot figure out which arguments to pass
I have this little problem. My client wanted two distinct swf on a web
I'm having a trouble with this little problem. Let's say, I have an array,
Alright, this problem is a little complicated, so bear with me. I have a
I have a little problem with following VHDL code: process (zbroji) begin if rising_edge(zbroji)
I have a little problem in my code. The variables don't want to change
I have a little problem. Essentially, the code: uint64_t myInteger = 98930 * 98930;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.