Close/Show of a DocumentContent when is set to Floating state

Aug 31, 2009 at 12:07 PM

Hi all. First i would like to say that AvalonDock is a great piece of work, which i hope that will personally give a solution to a lot of programming headaches.

However, i am new in using this, and i am facing the following problem:

1. I added a DocumentContent window (created in Xaml under the name of main3D2Dwindow) and added it in a documentpane (name CADHost) in the main window1 where the dockmanager exists. For this purpose i used: CADHost.Items.Add(main3D2Dwindow) that is invocked with the Window_Loaded. This works OK.

2. I added a button whick, when clicked will have to perform the following tasks:

- make this documentcontent Active if not (i used the SetAsActive())... This works OK

- if closed as documentcontent, to Add it again in the documentpane (i used the CADHost.Items.Add(main3D2Dwindow))... this works OK

- If is on a Floating Window state  and Closed, then "show" it again. Here i face the problem. The window floats normally and i Close it using the X button, but i cannot show it again!...I tried different methods but nothing seems to work.

if i use the dockmanager.Show(main3D2Dwindow) or

try to Add it again using the CADHost.Items.Add(main3D2Dwindow),

i always get the same error: "Element already has a logical parent. It must be detached from the old parent before it is attached to a new one."

I even tried to first use the Remove() and then Add() but i have the same problem.

I am sure that i am making a very basic error but i just cannot track it...

Any help is really appreciated.

Louis

 

 

 

 

Sep 4, 2009 at 12:29 PM
Edited Sep 4, 2009 at 12:30 PM

Yes its a bug, the showrt workaround is to add the following line before dockmanager.Show(main3D2Dwindow):

if (main3D2Dwindow.Parent != null)

{

        ((FloatingDockablePane)main3D2Dwindow.Parent).Items.Remove(main3D2Dwindow);

}

I fixed this in my internal version that I'll publish soon,

 

Many Thanks for this bug report

Ado

Sep 5, 2009 at 9:23 AM

Thanks Ado. Now it works as expected

Louis

Oct 1, 2009 at 8:20 PM

Ado,

I am using the version of this you posted on the 15th september and seem to be experiencing the same problem. Should this problem still exist? I tried the code you listed above and it didn't seem to help. This is how I try to reshow the window:

 

pane6.Items.Add(cont6);
            if (cont6.Parent != null)
            {
                ((FloatingDockablePane)cont6.Parent).Items.Remove(cont6);
            }
            dockManager.Show(cont6);

pane6.Items.Add(cont6);

            if (cont6.Parent != null)

            {

                ((FloatingDockablePane)cont6.Parent).Items.Remove(cont6);

            }

            dockManager.Show(cont6);

I get the error "Unable to cast object of type 'AvalonDock.DockablePane' to type 'AvalonDock.FloatingDockablePane'."

How should I be doing this?