private void FloatingPane_Closed(object sender, EventArgs e)
        {
            FloatingPane floatingPane = sender as FloatingPane;

            if (floatingPane.IViewContainer is InternalViewContainer)
            {
                ((InternalViewContainer)(floatingPane.IViewContainer)).Clear();
            }

            int count = floatingPane.IViewContainer.GetUserControlCount();

            for (int index = count - 1; index > -1; --index)
            {
                FrameworkElement userControl = floatingPane.IViewContainer.GetUserControl(index);
                IFloatingPaneHost.RemoveViewModel(userControl.DataContext as IViewModel);
            }

            if ((sender is FloatingToolPaneGroup) && (FloatingToolPaneGroups.Contains(sender as FloatingToolPaneGroup)))
            {
                FloatingToolPaneGroups.Remove(sender as FloatingToolPaneGroup);
            }

            if ((sender is FloatingDocumentPaneGroup) && (FloatingDocumentPaneGroups.Contains(sender as FloatingDocumentPaneGroup)))
            {
                FloatingDocumentPaneGroups.Remove(sender as FloatingDocumentPaneGroup);
            }
            CancelSelection();
        }
        private void FloatingPane_EndDrag(object sender, EventArgs e)
        {
            System.Diagnostics.Trace.Assert(sender is FloatingPane, System.Reflection.MethodBase.GetCurrentMethod().Name + ": sender not a FloatingPane");
            Application.Current.Dispatcher.Invoke(delegate
            {
                FloatingPane floatingPane = sender as FloatingPane;

                if (
                    (floatingPane == null) ||
                    ((SelectedPane != null) && !(SelectedPane is FloatingPane) && !(SelectedPane.Parent is SplitterPane) && !(SelectedPane.Parent is DocumentPanel) && (SelectedPane.Parent != IFloatingPaneHost.RootGrid)) ||
                    (_insertionIndicatorManager == null) ||
                    (_insertionIndicatorManager.WindowLocation == WindowLocation.None)
                    )
                {
                    if (floatingPane != null)
                    {
                        floatingPane.Close();
                    }
                    CancelSelection();
                    return;
                }

                ISelectablePane selectedPane  = SelectedPane;
                WindowLocation windowLocation = _insertionIndicatorManager.WindowLocation;
                CancelSelection();

                if (selectedPane is FloatingPane)
                {
                    IFloatingPane selectedFloatingPane = selectedPane as IFloatingPane;
                    selectedFloatingPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer);
                    if (floatingPane is FloatingToolPaneGroup)
                    {
                        FloatingToolPaneGroups.Remove(floatingPane);
                    }
                    else
                    {
                        FloatingDocumentPaneGroups.Remove(floatingPane);
                    }
                    floatingPane.Close();
                }
                else
                {
                    IFloatingPaneHost.Unfloat(floatingPane, selectedPane as SelectablePane, windowLocation);
                }

                Application.Current.MainWindow.Activate();
            });
        }