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...