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 715063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:08:42+00:00 2026-05-14T05:08:42+00:00

I’m trying to move a control from one parent to another (if this will

  • 0

I’m trying to move a control from one parent to another (if this will work I’m not quite sure). I can get a hold of the control that I want to move. Here is my code:

public void MoveElement(UIElement uiElement)
{
    var element = ((FrameworkElement)uiElement).Parent;
    //TODO:Remove from parent
    myControl.Children.Add(uiElement);
}

When I hit the last statment an ArgumentException is thrown stating “Specified Visual is already a child of another Visual or the root of a CompositionTarget.” The strange thing is that Parent is returning null. How do locate the parent? Will this even work?

EDIT: I don’t think actually moving an element is the answer to my problem. I’m working with the Visual Studio SDK and was able to get a hold of the UIElement that makes up the editor pane (extends DockPanel). I was trying to move the control from the standard editor into a custom tool window I’m developing.

This is proving to be a hack and I realized that I need multiple instances of the same control so I think a more complex solution (and less of a hack) is in store.

  • 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-05-14T05:08:42+00:00Added an answer on May 14, 2026 at 5:08 am

    The Parent property refers to the logical tree, and the docs note that “Parent may be null in cases where an element was instantiated, but is not attached to any logical tree that eventually connects to the page level root element, or the application object.” For example, the root element of a DataTemplate instantiated in a ListBox has a null Parent.

    Try using VisualTreeHelper.GetParent instead. The visual tree is the lower-level representation of how WPF elements are organised, and gives you access to all the extra “bits” that things like templating throw in there. For example, calling VisualTreeHelper.GetParent on the root element of a DataTemplate instantiated in a ListBox returns a ContentPresenter.

    Note that just because you can get hold of the parent visual does not necessarily mean you’ll be able to remove it. Some elements, such as Panels, provide methods for this. But if the element you locate is part of, say, a CheckBox, I don’t think you’ll be able to remove it.

    If you can provide a bit more context for what you’re trying to achieve by moving controls around the visual tree, people may be able to offer more specific advice or alternative approaches.

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

Sidebar

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.