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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:08:09+00:00 2026-05-17T20:08:09+00:00

So for my application I just have an image loaded and then in a

  • 0

So for my application I just have an image loaded and then in a grid in a tab item. After clicking on a button I create a new tab item with associated code to load other things. However, on going back to the first tab, I am met with this error:

“Must disconnect specified child from current parent Visual before attaching to new parent Visual.”

Specifically here:

    public class VisualsHost : FrameworkElement
{

    DrawingVisual _square;

    public VisualsHost()
    {
        _square = new DrawingVisual();
        this.Loaded += new RoutedEventHandler(OnLoaded);
    }

    public void OnLoaded(object sender, RoutedEventArgs e)
    {

        AddVisualChild(_square);
        AddLogicalChild(_square);
    }

This is just my container for my selection square I use for my content in the main tab.

So I am wondering, what exactly is happening here and how would I go about fixing this?

A brief structure of the content in my first tab is:

tabcontrol> dockpanel ->listbox -> grid (itemspanelcontainer style) -> listboxitems…

  • 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-17T20:08:10+00:00Added an answer on May 17, 2026 at 8:08 pm

    The Loaded event gets called each time you select the tab thus attempting to add _square again!

    The Loaded event is not necessarily only called once when first Loaded – the element can potentially be Loaded again for example if you were using system themes and changed your system theme all visual elements are re loaded.. In your case the visual tree is somehow being invalidated again – maybe because your binding to the Image is read again (if that is reason it may be good idea to change your binding to OneTime too). More info here: http://msdn.microsoft.com/en-us/library/ms754221.aspx and here: http://blogs.msdn.com/b/mikehillberg/archive/2006/09/19/loadedvsinitialized.aspx

    UPDATE: From a comment in the 2nd link above, applicable in your case:

    “If I may add the Loaded Event is also raised when ever a UI Element is loaded and unloaded. Such a case would be if you have a button named ‘x’ in Tab ‘A’, when the user switches to Tab ‘B’ an UnLoaded event is raised for x. When the user switches back to Tab A an Loaded event is raised for x, but not an Initialized event…”

    You should be able to confirm if this is indeed the case with a breakpoint while debugging. If it is: you could use a flag to prevent the event doing anything or remove the event after it has run:

    public class VisualsHost : FrameworkElement
    {
      bool hasLoaded = false;
      DrawingVisual _square;
    
      public VisualsHost()
      {
        _square = new DrawingVisual();
        this.Loaded += new RoutedEventHandler(OnLoaded);
      }
    
      public void OnLoaded(object sender, RoutedEventArgs e)
      {
        if(!hasLoaded)
        {
          AddVisualChild(this._square);
          AddLogicalChild(this._square);
          this.hasLoaded = true;
          this.Loaded -= OnLoaded; // unnecessary if using the hasLoaded flag
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing application with a new requirement to show an image in
I am just going to submit my iphone application . But I just have
I have just uploaded my published application files to my web server but I
I have just completed an application for my final year project and I need
I have just succeeded in creating oAuth authentication for my twitter application using PHP.
I have just added a Core Plot view to my application based on a
I have just been involved in writing an application that does not use Doctype's
I have just added a Telerik menu to my MVC application. I also have
I have just started using the Data Access Application Block from microsoft. There are
I have just tried to uploaded an app through the Application Loader, but it

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.