void Layout_ElementAdded(object sender, LayoutElementEventArgs e)
        {
            if (_suspendLayoutItemCreation)
                return;

            if (e.Element is LayoutDocument)
            {
                var document = e.Element as LayoutDocument;
                var documentItem = new LayoutDocumentItem();
                documentItem.Attach(document);
                ApplyStyleToLayoutItem(documentItem);
                _layoutItems.Add(documentItem);
            }
            else if (e.Element is LayoutAnchorable)
            {
                var anchorable = e.Element as LayoutAnchorable;
                var anchorableItem = new LayoutAnchorableItem();
                anchorableItem.Attach(anchorable);
                ApplyStyleToLayoutItem(anchorableItem);
                _layoutItems.Add(anchorableItem);
            }
            else if (e.Element is ILayoutContainer)
            {
                foreach (var document in e.Element.Descendents().OfType<LayoutDocument>().ToArray())
                {
                    var documentItem = new LayoutDocumentItem();
                    documentItem.Attach(document);
                    ApplyStyleToLayoutItem(documentItem);
                    _layoutItems.Add(documentItem);
                }
                foreach (var anchorable in e.Element.Descendents().OfType<LayoutAnchorable>().ToArray())
                {
                    var anchorableItem = new LayoutAnchorableItem();
                    anchorableItem.Attach(anchorable);
                    ApplyStyleToLayoutItem(anchorableItem);
                    _layoutItems.Add(anchorableItem);
                }
            }
        }
        void CreateDocumentLayoutItem(LayoutDocument contentToAttach)
        {
            if (_layoutItems.Any(item => item.LayoutElement == contentToAttach))
                return;

            var layoutItem = new LayoutDocumentItem();
            layoutItem.Attach(contentToAttach);
            ApplyStyleToLayoutItem(layoutItem);
            _layoutItems.Add(layoutItem);

            if (contentToAttach != null &&
                contentToAttach.Content != null &&
                contentToAttach.Content is UIElement)
            {
                InternalAddLogicalChild(contentToAttach.Content);
            }
        }
        void AttachLayoutItems()
        {
            if (Layout != null)
            {
                foreach (var document in Layout.Descendents().OfType<LayoutDocument>().ToArray())
                {
                    var documentItem = new LayoutDocumentItem();
                    documentItem.Attach(document);
                    ApplyStyleToLayoutItem(documentItem);
                    _layoutItems.Add(documentItem);
                }
                foreach (var anchorable in Layout.Descendents().OfType<LayoutAnchorable>().ToArray())
                {
                    var anchorableItem = new LayoutAnchorableItem();
                    anchorableItem.Attach(anchorable);
                    ApplyStyleToLayoutItem(anchorableItem);
                    _layoutItems.Add(anchorableItem);
                }

                Layout.ElementAdded += new EventHandler<LayoutElementEventArgs>(Layout_ElementAdded);
                Layout.ElementRemoved += new EventHandler<LayoutElementEventArgs>(Layout_ElementRemoved);
            }
        }