internal void StartDraggingFloatingWindowForContent(LayoutContent contentModel, bool startDrag = true)
        {
            if (!contentModel.CanFloat)
                return;
            var contentModelAsAnchorable = contentModel as LayoutAnchorable;
            if (contentModelAsAnchorable != null &&
                contentModelAsAnchorable.IsAutoHidden)
                contentModelAsAnchorable.ToggleAutoHide();

            var parentPane = contentModel.Parent as ILayoutPane;
            var parentPaneAsPositionableElement = contentModel.Parent as ILayoutPositionableElement;
            var parentPaneAsWithActualSize = contentModel.Parent as ILayoutPositionableElementWithActualSize;
            // ReSharper disable once PossibleNullReferenceException
            List<ILayoutElement> list = parentPane.Children.ToList();
            var contentModelParentChildrenIndex = list.IndexOf(contentModel);

            if (contentModel.FindParent<LayoutFloatingWindow>() == null)
            {
                ((ILayoutPreviousContainer)contentModel).PreviousContainer = parentPane;
                contentModel.PreviousContainerIndex = contentModelParentChildrenIndex;
            }

            parentPane.RemoveChildAt(contentModelParentChildrenIndex);

            double fwWidth = contentModel.FloatingWidth;
            double fwHeight = contentModel.FloatingHeight;

            if (fwWidth == 0.0)
                if (parentPaneAsPositionableElement != null) fwWidth = parentPaneAsPositionableElement.FloatingWidth;
            if (fwHeight == 0.0)
                if (parentPaneAsPositionableElement != null) fwHeight = parentPaneAsPositionableElement.FloatingHeight;

            if (fwWidth == 0.0)
                if (parentPaneAsWithActualSize != null) fwWidth = parentPaneAsWithActualSize.ActualWidth;
            if (fwHeight == 0.0)
                if (parentPaneAsWithActualSize != null) fwHeight = parentPaneAsWithActualSize.ActualHeight;

            LayoutFloatingWindow fw;
            LayoutFloatingWindowControl fwc;
            if (contentModel is LayoutAnchorable)
            {
                var anchorableContent = contentModel as LayoutAnchorable;
                fw = new LayoutAnchorableFloatingWindow
                {
                    RootPanel = new LayoutAnchorablePaneGroup(
                        new LayoutAnchorablePane(anchorableContent)
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            DockWidth = parentPaneAsPositionableElement.DockWidth,
                            DockHeight = parentPaneAsPositionableElement.DockHeight,
                            DockMinHeight = parentPaneAsPositionableElement.DockMinHeight,
                            DockMinWidth = parentPaneAsPositionableElement.DockMinWidth,
                            FloatingLeft = parentPaneAsPositionableElement.FloatingLeft,
                            FloatingTop = parentPaneAsPositionableElement.FloatingTop,
                            FloatingWidth = parentPaneAsPositionableElement.FloatingWidth,
                            FloatingHeight = parentPaneAsPositionableElement.FloatingHeight,
                        })
                };

                Layout.FloatingWindows.Add(fw);

                fwc = new LayoutAnchorableFloatingWindowControl((LayoutAnchorableFloatingWindow)fw)
                {
                    Width = fwWidth,
                    Height = fwHeight,
                    Left = contentModel.FloatingLeft,
                    Top = contentModel.FloatingTop
                };
            }
            else
            {
                var anchorableDocument = contentModel as LayoutDocument;
                fw = new LayoutDocumentFloatingWindow
                {
                    RootDocument = anchorableDocument
                };

                Layout.FloatingWindows.Add(fw);

                fwc = new LayoutDocumentFloatingWindowControl((LayoutDocumentFloatingWindow)fw)
                {
                    Width = fwWidth,
                    Height = fwHeight,
                    Left = contentModel.FloatingLeft,
                    Top = contentModel.FloatingTop
                };
            }

            _fwList.Add(fwc);

            Layout.CollectGarbage();

            UpdateLayout();

            Dispatcher.BeginInvoke(new Action(() =>
            {
                if (startDrag)
                    fwc.AttachDrag();
                fwc.Show();
            }), DispatcherPriority.Send);
        }
        // ReSharper disable once InconsistentNaming
        internal UIElement CreateUIElementForModel(ILayoutElement model)
        {
            var panel = model as LayoutPanel;
            if (panel != null)
                return new LayoutPanelControl(panel);
            var @group = model as LayoutAnchorablePaneGroup;
            if (@group != null)
                return new LayoutAnchorablePaneGroupControl(@group);
            var paneGroup = model as LayoutDocumentPaneGroup;
            if (paneGroup != null)
                return new LayoutDocumentPaneGroupControl(paneGroup);

            var side = model as LayoutAnchorSide;
            if (side != null)
            {
                var templateModelView = new LayoutAnchorSideControl(side);
                templateModelView.SetBinding(TemplateProperty, new Binding("AnchorSideTemplate") { Source = this });
                return templateModelView;
            }
            var anchorGroup = model as LayoutAnchorGroup;
            if (anchorGroup != null)
            {
                var templateModelView = new LayoutAnchorGroupControl(anchorGroup);
                templateModelView.SetBinding(TemplateProperty, new Binding("AnchorGroupTemplate") { Source = this });
                return templateModelView;
            }

            var documentPane = model as LayoutDocumentPane;
            if (documentPane != null)
            {
                var templateModelView = new LayoutDocumentPaneControl(documentPane);
                templateModelView.SetBinding(StyleProperty, new Binding("DocumentPaneControlStyle") { Source = this });
                return templateModelView;
            }
            var pane = model as LayoutAnchorablePane;
            if (pane != null)
            {
                var templateModelView = new LayoutAnchorablePaneControl(pane);
                templateModelView.SetBinding(StyleProperty, new Binding("AnchorablePaneControlStyle") { Source = this });
                return templateModelView;
            }

            var fw = model as LayoutAnchorableFloatingWindow;
            if (fw != null)
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return null;
                var modelFw = fw;
                var newFw = new LayoutAnchorableFloatingWindowControl(modelFw);
                newFw.SetParentToMainWindowOf(this);

                var paneForExtensions = modelFw.RootPanel.Children.OfType<LayoutAnchorablePane>().FirstOrDefault();
                if (paneForExtensions != null)
                {
                    //ensure that floating window position is inside current (or nearest) monitor
                    paneForExtensions.KeepInsideNearestMonitor();

                    newFw.Left = paneForExtensions.FloatingLeft;
                    newFw.Top = paneForExtensions.FloatingTop;
                    newFw.Width = paneForExtensions.FloatingWidth;
                    newFw.Height = paneForExtensions.FloatingHeight;
                }

                newFw.ShowInTaskbar = false;
                newFw.Show();
                // Do not set the WindowState before showing or it will be lost
                if (paneForExtensions != null && paneForExtensions.IsMaximized)
                {
                    newFw.WindowState = WindowState.Maximized;
                }
                return newFw;
            }

            var window = model as LayoutDocumentFloatingWindow;
            if (window != null)
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return null;
                var modelFw = window;
                var newFw = new LayoutDocumentFloatingWindowControl(modelFw);
                newFw.SetParentToMainWindowOf(this);

                var paneForExtensions = modelFw.RootDocument;
                if (paneForExtensions != null)
                {
                    //ensure that floating window position is inside current (or nearest) monitor
                    paneForExtensions.KeepInsideNearestMonitor();

                    newFw.Left = paneForExtensions.FloatingLeft;
                    newFw.Top = paneForExtensions.FloatingTop;
                    newFw.Width = paneForExtensions.FloatingWidth;
                    newFw.Height = paneForExtensions.FloatingHeight;
                }

                newFw.ShowInTaskbar = true;
                newFw.Show();
                // Do not set the WindowState before showing or it will be lost
                if (paneForExtensions != null && paneForExtensions.IsMaximized)
                {
                    newFw.WindowState = WindowState.Maximized;
                }
                return newFw;
            }

            var document = model as LayoutDocument;
            if (document != null)
            {
                var templateModelView = new LayoutDocumentControl { Model = document };
                return templateModelView;
            }

            return null;
        }